Doubly-linked list/Element definition: Difference between revisions

→‎{{header|Wren}}: Rewrote this as the task is about element definition rather than the definition of the doubly-linked list itself.
(Added Wren)
(→‎{{header|Wren}}: Rewrote this as the task is about element definition rather than the definition of the doubly-linked list itself.)
Line 1,005:
=={{header|Wren}}==
{{libheader|Wren-llist}}
The DLinkedListDNode class in the above module is the element type for the DLinkedList class which is a generic doubly-linked list. andThe latter is implemented in such a way that circularthe loopsuser aredoes not possible.need Weto thereforedeal usedirectly with DNode though for the purposes of the task we show below how instances of it herecan be created and manipulated.
<lang ecmascript>import "/llist" for DLinkedListDNode
 
var dlldn1 = DLinkedListDNode.new(1)
forvar (idn2 in 1..3)= dllDNode.addnew(i2)
dn1.next = dn2
System.print(dll)
dn1.prev = null
for (i in 1..3) dll.remove(i)
dn2.prev = dn1
System.print(dll)</lang>
dn2.next = null
System.print(["node 1", "data = %(dn1.data)", "prev = %(dn1.prev)", "next = %(dn1.next)"])
System.print(["node 2", "data = %(dn2.data)", "prev = %(dn2.prev)", "next = %(dn2.next)"])</lang>
 
{{out}}
<pre>
[node 1, data = 1, prev = null, next = 2]
[1 <-> 2 <-> 3]
[node 2, data = 2, prev = 1, next = null]
[]
</pre>
 
9,476

edits