Doubly-linked list/Traversal: Difference between revisions
Content added Content deleted
(→{{header|Tcl}}: added zkl) |
|||
Line 1,191: | Line 1,191: | ||
say $dll.reverse;</lang> |
say $dll.reverse;</lang> |
||
These automatically return just the payloads, hiding the elements containing the forward and backward pointers. |
These automatically return just the payloads, hiding the elements containing the forward and backward pointers. |
||
=={{header|Phix}}== |
|||
<lang Phix>enum NEXT,PREV,DATA |
|||
constant empty_dll = {{1,1}} |
|||
sequence dll = empty_dll |
|||
procedure insert_after(object data, integer pos=1) |
|||
integer prv = dll[pos][PREV] |
|||
dll = append(dll,{pos,prv,data}) |
|||
if prv!=0 then |
|||
dll[prv][NEXT] = length(dll) |
|||
end if |
|||
dll[pos][PREV] = length(dll) |
|||
end procedure |
|||
insert_after("ONE") |
|||
insert_after("TWO") |
|||
insert_after("THREE") |
|||
?dll |
|||
procedure show(integer d) |
|||
integer idx = dll[1][d] |
|||
while idx!=1 do |
|||
?dll[idx][DATA] |
|||
idx = dll[idx][d] |
|||
end while |
|||
end procedure |
|||
show(NEXT) |
|||
?"==" |
|||
show(PREV)</lang> |
|||
{{out}} |
|||
<pre> |
|||
{{2,4},{3,1,"ONE"},{4,2,"TWO"},{1,3,"THREE"}} |
|||
"ONE" |
|||
"TWO" |
|||
"THREE" |
|||
"==" |
|||
"THREE" |
|||
"TWO" |
|||
"ONE" |
|||
</pre> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |