Singly-linked list/Element definition: Difference between revisions

→‎{{header|Wren}}: Rewrote this as the task is about element definition rather than the definition of the singly-linked list itself.
(Added Wren)
(→‎{{header|Wren}}: Rewrote this as the task is about element definition rather than the definition of the singly-linked list itself.)
Line 1,794:
=={{header|Wren}}==
{{libheader|Wren-llist}}
The LinkedListNode class in the above module is the element type for the LinkedList class which is a generic singly-linked list. andThe solatter is implemented in such a way that the user does not need to deal drectly with Node though for the purposes of the task we useshow below how instances of it herecan be created and manipulated.
<lang ecmascript>import "/llist" for LinkedListNode
 
var lln1 = LinkedListNode.new(1)
forvar (in2 in 1..3)= llNode.addnew(i2)
n1.next = n2
System.print(ll)
System.print(["node 1", "data = %(n1.data)", "next = %(n1.next)"])
for (i in 1..3) ll.remove(i)
System.print(ll["node 2", "data = %(n2.data)", "next = %(n2.next)"])</lang>
 
{{out}}
<pre>
[node 1, ->data 2= ->1, 3next = 2]
[node 2, data = 2, next = null]
[]
</pre>
 
9,487

edits