Singly-linked list/Reversal: Difference between revisions
Content added Content deleted
imported>StraightDoubt (Added Common Lisp with various examples) |
m (→{{header|Wren}}: Minor tidy) |
||
Line 613: | Line 613: | ||
However, it's also possible to reverse the LinkedList in place by successively exchanging elements at both ends. Internally, the 'exchange' method uses the indexer to swap elements. |
However, it's also possible to reverse the LinkedList in place by successively exchanging elements at both ends. Internally, the 'exchange' method uses the indexer to swap elements. |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="wren">import "./llist" for LinkedList |
||
import "./iterate" for Reversed |
import "./iterate" for Reversed |
||
Line 630: | Line 630: | ||
// iterate backwards by creating a list internally |
// iterate backwards by creating a list internally |
||
for (e in Reversed.new(sll)) System.write("%(e) ") |
for (e in Reversed.new(sll)) System.write("%(e) ") |
||
System.print() |
System.print("\n") |
||
// reverse the linked list in place |
// reverse the linked list in place |