Difference between revisions of "Linklist.getposition"

From OpenEUO
Jump to: navigation, search
(Created page with "== Calling Pattern == Call local k = sl.linklist() -- later local n = k.getposition(a[,b]) Arguments a is a number b optional, is a boolean Results n is a number == Exam...")
 
m (See Also)
Line 35: Line 35:
 
* [[deque]]
 
* [[deque]]
  
 +
* [[linklist]]
 
* [[linklist.head]]
 
* [[linklist.head]]
 
* [[linklist.insertafter]]
 
* [[linklist.insertafter]]

Revision as of 13:34, 18 December 2010

Calling Pattern

Call

local k = sl.linklist()
-- later
local n = k.getposition(a[,b])

Arguments

a is a number
b optional, is a boolean

Results

n is a number

Example Usage

local k = sl.linklist()
local j = k.insertb(0,'one')
local j0 = j
j = k.insertb(j,'two')
j = k.insertb(j,'three')
print(k.getpos(j0))
print(k.getpos(j))
--> 3
    1 

Description

Calling getposition returns the absolute position of a link psuedo-index relative to the head of the list. If b is specified and has a value of false then getposition returns the position relative to the tail of the list. Positions run from 1 to the length of the linked list.

See Also