Singly-linked list/Element definition: Difference between revisions
Singly-linked list/Element definition (view source)
Revision as of 08:57, 27 June 2024
, 14 days agoPascalABC.NET
imported>Chinhouse |
(PascalABC.NET) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 983:
=={{header|MiniScript}}==
Implementing linked lists in MiniScript is an academic exercise. For practical applications, use the built-in list type.
<syntaxhighlight lang="miniscript">
Node = {"item": null, "next": null}
Line 1,002 ⟶ 1,003:
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
LinkedList.traverse = function
cursor = self.head
while cursor != null
// do stuff
print cursor.item
cursor = cursor.next
end while
end function
test = new LinkedList
test.append("A")
test.append("B")
test.insert("A","C")
test.traverse
</syntaxhighlight>
Line 1,309 ⟶ 1,337:
FData: integer;
end;</syntaxhighlight>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
type Node<T> = auto class
data: T;
next: Node<T>;
end;
</syntaxhighlight>
=={{header|Perl}}==
Line 1,990 ⟶ 2,026:
{{libheader|Wren-llist}}
The Node class in the above module is the element type for the LinkedList class which is a generic singly-linked list. The latter is implemented in such a way that the user does not need to deal directly with Node though for the purposes of the task we show below how instances of it can be created and manipulated.
<syntaxhighlight lang="
var n1 = Node.new(1)
|