Difference between revisions of "LL Push"

Line 1: Line 1:
== LL_Push( LL, x ) ==
+
== 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.
 
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]].
 
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 ==
 
== Examples ==
 
+
This returns a linked list with one element, <code>a</code>:
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.
 
This transforms a list of tokens into a linked list, but in reverse order.
[[Var]] L := [ 10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1' ];
+
:<code>Var L := [10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1'];</code>
[[Var]] LL := null;
+
:<code>Var LL := null;</code>
[[For]] x := L Do LL := [[LL_Push]](LL, x);
+
:<code>For x := L Do LL := LL_Push(LL, x);</code>
LL
+
:<code>LL</code>
  
 
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.
 
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' ];
+
:<code>Var L := [10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1'];</code>
[[Var]] LL := [[Null]];
+
:<code>Var LL := Null;</code>
[[For]] i := [[Size]](L)..1 Do LL := [[LL_Push]](LL, [[Slice]](L,i));
+
:<code>For i := Size(L)..1 Do LL := LL_Push(LL, Slice(L, i));</code>
LL
+
:<code>LL</code>
  
 
== See also ===
 
== See also ===
 
 
* [[Linked list library]]
 
* [[Linked list library]]
 
* [[LL_To_RArray]]
 
* [[LL_To_RArray]]

Revision as of 02:01, 29 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.