Linklist.insertbefore
From OpenEUO
Revision as of 13:52, 18 December 2010 by Ximan (Talk | contribs) (Created page with "== Calling Pattern == Call local k = sl.linklist() -- later local n = k.insertbefore(a,b) Arguments a is a number b is any value Results n is a number == Example Usage =...")
Calling Pattern
Call
local k = sl.linklist() -- later local n = k.insertbefore(a,b)
Arguments
a is a number b is any value
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 insertbefore creates a new link with value b and inserts it before the link with psuedo-index a. If the list is empty, a can be any number and the new link is also the head and tail of the list. If the list is non-empty and a is not a valid pseudo-index, then insertbefore fails and returns 0.