Doubly-linked list/Element definition: Difference between revisions

Content added Content deleted
(→‎{{header|AutoHotkey}}: moved to new url)
(Added PicoLisp)
Line 371: Line 371:
P = P => back_pointer; /* P now points at the previous node. */
P = P => back_pointer; /* P now points at the previous node. */
</lang>
</lang>

=={{header|PicoLisp}}==
We use (in addition to the header structure described in
[[Doubly-linked list/Definition#PicoLisp]])
two cells per doubly-linked list element:

+-----+-----+ +-----+-----+
| Val | ---+---> | | | ---+---> next
+-----+-----+ +--+--+-----+
|
prev <---+

With that, 'cddr' can be used to access the next, and 'cadr' to access the
previous element.
<lang PicoLisp># 'cons' an element to a doubly-linked list
(de 2cons (X DLst)
(let L (car DLst) # Get current data list
(set DLst (cons X NIL L)) # Prepend two new cons pairs
(if L # Unless DLst was empty
(set (cdr L) (car DLst)) # set new 'prev' link
(con DLst (car DLst)) ) ) ) # otherwise set 'end' link

# We prepend 'not' to the list in the previous example
(2cons 'not *DLst)</lang>
For output of the example data, see [[Doubly-linked list/Traversal#PicoLisp]].


=={{header|Pop11}}==
=={{header|Pop11}}==