Singly-linked list/Element insertion: Difference between revisions

no edit summary
(→‎{{header|REXX}}: refurbished and extended the output)
imported>Chinhouse
No edit summary
Line 1,540:
->{a, b, c}</syntaxhighlight>
 
Node = {"item": null, "next": null}
Node.init = function(item)
node = new Node
node.item = item
return node
end function
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
LinkedList = {"head": null, "tail": null}
LinkedList.append = function(item)
newNode = Node.init(item)
if self.head == null then
self.head = newNode
self.tail = self.head
else
self.tail.next = newNode
self.tail = self.tail.next
end if
end function
 
LinkedList.insert = function(aftItem, item)
newNode = Node.init(item)
cursor = self.head
while cursor.item != aftItem
print cursor.item
cursor = cursor.next
end while
newNode.next = cursor.next
cursor.next = newNode
end function
 
test = new LinkedList
test.append("A")
test.append("B")
test.insert("A","C")
</syntaxhighlight>
=={{header|Modula-3}}==
<syntaxhighlight lang="modula3">MODULE SinglyLinkedList EXPORTS Main;
Anonymous user