Delphi-LinkedList
Generic Linked List Delphi implementation inspired by C# TLinkedList class
- Quiet · last change 2-7-2024
- ★ 1 on GitHub
README
Delphi-TLinkedList
Generic Linked List Delphi implementation from C# TLinkedList class
Description
TLinkedList<T> is a general-purpose linked list. TLinkedList<T> provides separate nodes of type TNode<T>, so insertion and removal are O(1) operations. You can remove nodes and reinsert them, either in the same list or in another list, which results in no additional objects allocated on the heap. Because the list also maintains an internal count, getting the Count property is an O(1) operation. Each node in a TLinkedList<T> object is of the type TNode<T>. Because the TLinkedList<T> is doubly linked, each node points forward to the Next node and backward to the Previous node. TLinkedList<T> accepts null as a valid Value property for reference types and allows duplicate values. If the LinkedList<T> is empty, the First and Last properties contain null.
Installation
Just import LinkedList.pas in your project or in the IDE library
Methods and Properties
- Create: Initializes a new instance of the TLinkedList<T> class.
- Destroy: Destroys the linked list and its elements.
- AddFirst(Value: T): Adds a new node with the specified value at the beginning of the linked list.
- AddLast(Value: T): Adds a new node with the specified value at the end of the linked list.
- RemoveFirst: Removes and returns the value of the first node in the linked list.
- RemoveLast: Removes and returns the value of the last node in the linked list.
- Remove(Value: T): Boolean: Removes the first occurrence of the specified value from the linked list.
- Clear: Removes all nodes from the linked list.
- Contains(Value: T): Boolean: Determines whether the linked list contains a specific value.
- CopyTo(var ArrayOfT: array of T; Index: Integer): Copies the elements of the linked list to an array, starting at a particular index in the array.
- ElementAt(Index: Integer): T: Returns the value at the specified index in the linked list.
- First: T: Returns the value of the first node in the linked list.
- Last: T: Returns the value of the last node in the linked list.
- IndexOf(Value: T): Integer: Returns the index of the first occurrence of a specific value in the linked list.
- RemoveAt(Index: Integer): T: Removes the node at the specified index in the linked list and returns its value.
- Count: Integer: Returns the number of nodes in the linked list.
- FirstNode: TNode<T>: Property to get the first node in the linked list.
- LastNode: TNode<T>: Property to get the last node in the linked list.

