Singly-linked list/Reversal: Difference between revisions

Content added Content deleted
(Added Algol 68)
Line 8: Line 8:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Using the code from the [[Singly-linked list/Traversal#ALGOL_68]] Task
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">
<syntaxhighlight lang="algol68">
BEGIN
BEGIN
Line 24: Line 26:
REF STRINGLIST reverse := REF STRINGLIST(NIL);
REF STRINGLIST reverse := REF STRINGLIST(NIL);
WHILE node ISNT REF STRINGLIST(NIL) DO
WHILE node ISNT REF STRINGLIST(NIL) DO
reverse := HEAP STRINGLIST
reverse := HEAP STRINGLIST
:= STRINGLIST( value OF node, reverse );
:= STRINGLIST( value OF node, reverse );
print((value OF node, space));
print((value OF node, space));