Singly-linked list/Reversal: Difference between revisions

(Added Algol 68)
Line 8:
=={{header|ALGOL 68}}==
Using the code from the [[Singly-linked list/Traversal#ALGOL_68]] Task
<br>LOC and HEAP are like NEW in other languages. LOC generates a new item on the stack and HEAP a new item on the heap (which is garbage collected).
<br>The use of LOC in the outermost level if OK as the generated elements will exist until the final END, but HEAP must be used in the loop creating the reverse list elements, to ensure they still exist when the loop exits.
<syntaxhighlight lang="algol68">
BEGIN
Line 24 ⟶ 26:
REF STRINGLIST reverse := REF STRINGLIST(NIL);
WHILE node ISNT REF STRINGLIST(NIL) DO
reverse := HEAP STRINGLIST
:= STRINGLIST( value OF node, reverse );
print((value OF node, space));
3,045

edits