Doubly-linked list/Element definition: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 651: Line 651:
With that, 'cddr' can be used to access the next, and 'cadr' to access the
With that, 'cddr' can be used to access the next, and 'cadr' to access the
previous element.
previous element.
<lang PicoLisp># 'cons' an element to a doubly-linked list
<lang PicoLisp>
(de 2cons (X DLst)
(de 2head (X DLst)
(let L (car DLst) # Get current data list
(let L (car DLst) # Get current data list
(set DLst (cons X NIL L)) # Prepend two new cons pairs
(set DLst (cons X NIL L)) # Prepend two new cons pairs
Line 660: Line 660:


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