Difference between revisions of "LL Push"
m (adding doc status category stub page) |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | [[Category: | + | [[Category:Linked list library functions]] |
+ | |||
+ | == 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]]. | ||
+ | |||
+ | ==Library== | ||
+ | [[Linked list library]] ([[media:Linked List Library.ana|Linked List Library.ana]]) | ||
+ | :Use [[File menu|File]] → '''Add Library...''' to add this library | ||
+ | |||
+ | == Examples == | ||
+ | This returns a linked list with one element, <code>a</code>: | ||
+ | :<code>LL_Push(null, 'a')</code> | ||
+ | |||
+ | This transforms a list of tokens into a linked list, but in reverse order. | ||
+ | :<code>Var L := [10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1'];</code> | ||
+ | :<code>Var LL := null;</code> | ||
+ | :<code>For x := L Do LL := LL_Push(LL, x);</code> | ||
+ | :<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. | ||
+ | :<code>Var L := [10, '+', 20, '*', '(', '5', '-', 2, '^', 3, ')', '^', 2, '-', '1'];</code> | ||
+ | :<code>Var LL := Null;</code> | ||
+ | :<code>For i := Size(L)..1 Do LL := LL_Push(LL, Slice(L, i));</code> | ||
+ | :<code>LL</code> | ||
+ | |||
+ | == See also == | ||
+ | * [[Linked list library]] | ||
+ | * [[media:Linked List Library.ana|Linked List Library.ana]] | ||
+ | * [[LL_To_RArray]] | ||
+ | * [[LL_To_Array]] | ||
+ | * [[LL_Remove_First]] | ||
+ | * [[Subset]] | ||
+ | * [[Slice assignment]] |
Latest revision as of 19:58, 24 May 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.
Library
Linked list library (Linked List Library.ana)
- Use File → Add Library... to add this 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
Enable comment auto-refresher