Difference between revisions of "LL Push"

Line 1: Line 1:
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
 
 
 
== LL_Push( LL, x ) ==
 
== LL_Push( LL, x ) ==
  
Line 10: Line 8:
 
== Examples ==
 
== Examples ==
  
 +
This returns a linked list with one element, 'a':
 
:<code>LL_Push( null, 'a' )</code>
 
:<code>LL_Push( null, 'a' )</code>
 +
 +
This transforms a list of tokens into a linked list, but in reverse order.
 +
[[Var]] L := [ 10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1' ];
 +
[[Var]] LL := null;
 +
[[For]] x := L Do LL := [[LL_Push]](LL, x);
 +
LL
 +
 +
An algorithm that evaluates infix operators with different levels of operator precedence may want to start with tokens pushed onto a linked list in forward order.
 +
[[Var]] L := [ 10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1' ];
 +
[[Var]] LL := [[Null]];
 +
[[For]] i := [[Size]](L)..1 Do LL := [[LL_Push]](LL, [[Slice]](L,i));
 +
LL
  
 
== See also ===
 
== See also ===

Revision as of 22:02, 28 January 2016

LL_Push( LL, x )

Pushes «x» onto the front of the linked list «LL», returning a new linked list with one element more than the original «LL». «LL» itself is not changed. This function is part of the Linked list library. You can use this function to build up a collection of items when you don't know in advance how many items there will be.

To use this function, you must use Add Library... on the File menu to add the Linked list library to your model. For more on the use of linked lists, see Linked list library.


Examples

This returns a linked list with one element, 'a':

LL_Push( null, 'a' )

This transforms a list of tokens into a linked list, but in reverse order.

Var L := [ 10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1' ];
Var LL := null;
For x := L Do LL := LL_Push(LL, x);
LL

An algorithm that evaluates infix operators with different levels of operator precedence may want to start with tokens pushed onto a linked list in forward order.

Var L := [ 10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1' ];
Var LL := Null;
For i := Size(L)..1 Do LL := LL_Push(LL, Slice(L,i));
LL

See also =

Comments


You are not allowed to post comments.