Class LinkedList<T>
- Namespace
- AlgorithmsSW.List
- Assembly
- AlgorithmsSW.dll
Represents a singly linked list.
public sealed class LinkedList<T> : IEnumerable<T>, IEnumerable
Type Parameters
T
The type of elements in the LinkedList<T>.
- Inheritance
-
LinkedList<T>
- Implements
-
IEnumerable<T>
- Inherited Members
- Extension Methods
Properties
Count
Gets the number of elements contained in the LinkedList<T>.
public int Count { get; }
Property Value
First
Gets the first node of the LinkedList<T>.
public LinkedList<T>.Node First { get; }
Property Value
- LinkedList<T>.Node
Exceptions
- InvalidOperationException
Thrown when the LinkedList<T> is empty.
IsEmpty
Gets a value indicating whether the linked list is empty.
public bool IsEmpty { get; }
Property Value
IsSingleton
Gets a value indicating whether the linked list has only one item.
public bool IsSingleton { get; }
Property Value
Last
Gets the last node of the linked list.
public LinkedList<T>.Node Last { get; }
Property Value
- LinkedList<T>.Node
Exceptions
- InvalidOperationException
Thrown when the linked list is empty.
Nodes
Gets an enumerable collection of nodes in the linked list.
public IEnumerable<LinkedList<T>.Node> Nodes { get; }
Property Value
Methods
Clear()
Removes all nodes from this LinkedList<T>.
public void Clear()
Concat(LinkedList<T>)
Concatenates the current LinkedList<T> with another LinkedList<T>.
public void Concat(LinkedList<T> other)
Parameters
other
LinkedList<T>The LinkedList<T> to concatenate with.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
InsertAfter(Node, T)
Inserts a new item after the specified node in the linked list.
[ExerciseReference(1, 3, 25)]
public LinkedList<T>.Node InsertAfter(LinkedList<T>.Node node, T item)
Parameters
node
LinkedList<T>.NodeThe node after which to insert the new item.
item
TThe item to insert.
Returns
- LinkedList<T>.Node
The newly created node containing the inserted item.
InsertAtBack(T)
Inserts a new item at the end of the linked list.
public LinkedList<T>.Node InsertAtBack(T item)
Parameters
item
TThe item to insert.
Returns
- LinkedList<T>.Node
The newly created node containing the inserted item.
InsertAtFront(T)
Inserts a new item at the beginning of the linked list.
public LinkedList<T>.Node InsertAtFront(T item)
Parameters
item
TThe item to insert.
Returns
- LinkedList<T>.Node
The newly created node containing the inserted item.
RemoveAfter(Node)
Removes the node after the specified node.
[ExerciseReference(1, 3, 24)]
public LinkedList<T>.Node RemoveAfter(LinkedList<T>.Node node)
Parameters
node
LinkedList<T>.NodeThe node whose successor is to be removed.
Returns
- LinkedList<T>.Node
The removed node.
Exceptions
- ArgumentNullException
Thrown when the input node is null.
- InvalidOperationException
Thrown when the input node does not have a successor to remove.
RemoveFromFront()
Removes the first item from the linked list.
public LinkedList<T>.Node RemoveFromFront()
Returns
- LinkedList<T>.Node
The removed node.
Reverse()
Reverses the order of the nodes in the linked list.
[ExerciseReference(1, 3, 30)]
public void Reverse()
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.