CLinkedList Class
Basic Linked list class with some interfaces implemented to work with WPF UI elements
CLinkedList class, is a custom C# generic class implementing basic Doubly linked list operations with some extra features for ease of use and better integration with other .Net classes especially for WPF UI elements. We chose the class to be generic so the list elements can be of any type chosen by the end user
CLinkedList Class
Namespace: TASLibrary.CustomDataStructures Assembly: TASLibrary.dll
Represents a doubly linked list.
public class CLinkedList<T> :
ICollection<T>,
IEquatable<CLinkedList<T>>,
ISerializable,
IDeserializationCallback,
INotifyCollectionChanged
where T : class {}Type Parameters
T Specifies the element type of the linked list.
Implements
ICollection<T>, IEquatable<T>, ISerializable, IDeserializationCallback, INotifyCollectionChanged
Remarks
CLinkedList is a general-purpose linked list. It supports enumerators and implements the ICollection interface, consistent with other collection classes in the .NET Framework.
CLinkedList provides separate nodes of type CNode, so insertion and removal are O(1) operations.
The list maintains an internal count, getting the Count property is an O(1) operation.
Each node in a CLinkedList object is of the type CNode. Because the CLinkedList is doubly linked, each node points forward to the Next node and backward to the Previous node.
If the CLinkedList is empty, the First and Last properties contain null.
The CLinkedList class does not support chaining, splitting, cycles, or other features that can leave the list in an inconsistent state.
Class Members
Private Members:
_head: The first node in the list of typeCNode<T>.
_tail: The last node in the list of typeCNode<T>.
_count: Nodes count in the list of typeint.
_siInfo; Serialization data used while deserialization of the TypeSerializationInfo.
Public Members
First: Gets the first element in the list of typeT.
Last: Gets the last element in the list of typeT.
Count: Gets the number of nodes actually contained in the list.
IsReadOnly; Determines if the class is read only or not of typebool.
Private Methods
AddNodeToEmptyList(CNode<T>)
AddNodeToEmptyList(CNode<T>)Adds the specified node to an empty list.
InternalFind(int)
InternalFind(int)Finds the node at the specified index.
InternalFind(T)
InternalFind(T)Finds the node that contains the same specified data.
CreateList(T[])
CreateList(T[])Initializes the list after deserialization from the specified array.
Public Methods
this[int]
this[int]Gets or sets the element at the specified index.
AddLast(T)
AddLast(T)Adds a new node containing the specified value at the end of the list.
AddFirst(T)
AddFirst(T)Adds a new node containing the specified value at the start of the list.
RemoveLast()
RemoveLast()Removes the node at the end of the list.
RemoveFirst()
RemoveFirst()Removes the node at the start of the list.
Remove(T)
Remove(T)Removes the first occurrence of the specified value from the list.
RemoveAt(int)
RemoveAt(int)Removes the node at the specified index from the list.
Clear()
Clear()Removes all nodes from the list.
Find(T)
Find(T)Finds the first node that contains the specified value.
Find(Predicate<T>)
Find(Predicate<T>)Finds the first node that matches the specified predicate.
FindAll(Predicate<T>)
FindAll(Predicate<T>)Finds all the nodes that match the specified predicate.
ToString()
ToString()Returns a string that represents the current object. (Override)
ToString(string)
ToString(string)Returns a string that represents the current object with the list name inserted to it.
Defines methods to manipulate generic collections.
GetEnumerator()
GetEnumerator()Returns an enumerator that iterates through the linked list as a collection.
Add()
Add()Adds an item at the end of the list.
CopyTo(T[], int)
CopyTo(T[], int)Copies the entire list to a compatible one-dimensional Array, starting at the specified index of the target array.
Contains(T)
Contains(T)Checks if a given element exists in the list.
Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.
Equals(CLinkedList<T>)
Equals(CLinkedList<T>)Determines whether the specified object is equal to the current object.
Equals(CLinkedList<T>)
Equals(CLinkedList<T>)Determines whether the specified object is equal to the current object. (Override)
GetHashCode
GetHashCodeServes as the default hash function.
==(CLinkedList<T>, CLinkedList<T>)
==(CLinkedList<T>, CLinkedList<T>)Determines whether the first object is equal to the other object.
!=(CLinkedList<T>, CLinkedList<T>)
!=(CLinkedList<T>, CLinkedList<T>)Determines whether the first object is not equal to the other object.
Allows an object to control its own serialization and deserialization.
GetObjectData(SerializationInfo, StreamingContext)
GetObjectData(SerializationInfo, StreamingContext)Implements the ISerializable interface and returns the data needed to serialize the list instance.
CLinkedList<>(SerializationInfo, StreamingContext)
CLinkedList<>(SerializationInfo, StreamingContext)Initializes a new instance of the CLinkedList class that is serializable with the specified SerializationInfo and StreamingContext.
Indicates that a class is to be notified when deserialization of the entire object graph has been completed.
OnDeserialization(object sender)
OnDeserialization(object sender)Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.
Notifies listeners of dynamic changes, such as when an item is added and removed or the whole list is cleared.
CollectionChanged
CollectionChangedOccurs when the collection changes.
Last updated
Was this helpful?