LinkedList<T> Methods in C#
DevSniper
173 Views
Methods
- AddLast(T) :- public System.Collections.Generic.LinkedListNode<T> AddLast (T value);it will add new node with specified value at the end of the LinkedList<T> and return that node (new LinkedListNode<T>). It is an O(1) operation.
- AddLast(LinkedListNode<T>) :- public void AddLast (System.Collections.Generic.LinkedListNode<T> node);It will add the provided node at the end of the LinkedList<T>. It is an O(1) operation.
- AddFirst(T) :- public System.Collections.Generic.LinkedListNode<T> AddFirst (T value);it will add new node with specified value at the start of the LinkedList<T> and return that node (new LinkedListNode<T>). It is an O(1) operation.
- AddFirst(LinkedListNode<T>) :- public void AddFirst (System.Collections.Generic.LinkedListNode<T> node);It will add the provided node at the start of the LinkedList<T>. It is an O(1) operation.
- AddBefore(LinkedListNode<T>, T) :- public System.Collections.Generic.LinkedListNode<T> AddBefore (System.Collections.Generic.LinkedListNode<T> node, T value);it will add new node with the specified value in LinkedList<T> before the specified existing node and return that newly added node (new LinkedListNode<T>) with specified value. It is an O(1) operation.
- AddBefore(LinkedListNode<T>,LinkedListNode<T>) :- public void AddBefore (System.Collections.Generic.LinkedListNode<T> node, System.Collections.Generic.LinkedListNode<T> newNode);It will add the provided newNode in the LinkedList<T> before the specified existing node. It is an O(1) operation.
- AddAfter(LinkedListNode<T>,T) :- public System.Collections.Generic.LinkedListNode<T> AddAfter (System.Collections.Generic.LinkedListNode<T> node, T value);it will add new node with the specified value in LinkedList<T> after the specified existing node and return that newly added node (new LinkedListNode<T>) with specified value. It is an O(1) operation.
- AddAfter(LinkedListNode<T>,LinkedListNode<T>) :- public void AddAfter (System.Collections.Generic.LinkedListNode<T> node, System.Collections.Generic.LinkedListNode<T> newNode);It will add the provided newNode in the LinkedList<T> after the specified existing node. It is an O(1) operation.
- Clear :- public void Clear ();It will remove all nodes from the LinkedList<T>. It is an O(n) operation.
- Contains(T) :- public bool Contains (T value);Returns true if value is present in the LinkedList<T> otherwise false. to check this method perform liner search on LinkedList<T> so the time complexity of this operation is O(n).
- CopyTo(T,int) :- public void CopyTo (T[] array, int index);It will Copy LinkedList<T> elements into provided 1-D array from index, arrayIndex passed by params (zero-based index) . It is an O(n) operation.
- Find(T) :- public System.Collections.Generic.LinkedListNode<T>? Find (T value);It will find the first node that contains the specified value and return that node if there is no node with specified value in the LinkedList<T> it returns null. This method performs a linear search, so the time complexity of this method is O(n).
- FindLast (T) :- public System.Collections.Generic.LinkedListNode<T>? FindLast (T value);Find the last node that has the specified value and return that node, return null if there is no node exist with specified value. This method performs a linear search, so the time complexity of this method is O(n).
- RemoveFirst :- public void RemoveFirst ();it will remove first node of the LinkedList<T>. throw InvalidOperationException if the LinkedList<T> is Empty. time complexity of this method is O(1).
- RemoveLast :- public void RemoveLast ();It will remove last node of the LinkedList<T>. throw InvalidOperationException if the LinkedList<T> is Empty . The time complexity of this method is O(1).
- Remove (T) :- public bool Remove (T value);It will remove the first occurrence of the specified value node. Returns true if value found and removed otherwise false ( if value not found). This method performs a linear search to find the specified value so the time complexity of this method is O(n).
- Remove(LinkedListNode<T>) :- public void Remove (System.Collections.Generic.LinkedListNode<T> node);it will remove the specified node form the LinkedList<T> and throw InvalidOperationException if node not present in the current LinkedList<T>.
- Equals(Object) :- public virtual bool Equals (object? obj);Returns true if specified object is equals to the current object otherwise false.
- GetEnumerator :- public System.Collections.Generic.LinkedList<T>.Enumerator GetEnumerator ();it will return an enumerator of the LinkedList<T>. it is an O(1) operation.
- GetHashCode :- public virtual int GetHashCode ();Returns a hash code of current object.
- GetType :- public Type GetType ();Returns the exact runtime type of current instance.
- MemberwiseClone :- protected object MemberwiseClone ();it will creates and return a shallow copy of the current Object.
- ToString :- public virtual string? ToString ();It will return a string that represents the current object.
- OnDeserialization(Object) :- public virtual void OnDeserialization (object? sender);