/// <summary>Inserts an item at front of the linked list</summary> /// <param name="data">The data.</param> public void InsertFront(T data) { DirectionNode <T> newNode = new DirectionNode <T>(data); if (_head == null && _tail == null) { _head = newNode; _tail = newNode; _head.next = _tail; _head.prev = _tail; _tail.next = _head; _tail.prev = _head; } else { newNode.next = _head; newNode.prev = _tail; if (_head != null) { _head.prev = newNode; } if (_tail != null) { _tail.next = newNode; } _head = newNode; } }
/// <summary>Gets the node by key.</summary> /// <param name="key">The key.</param> /// <returns></returns> public DirectionNode <T> GetNodeByKey(T key) { DirectionNode <T> temp = _head; while (temp != null && !EqualityComparer <T> .Default.Equals(temp.value, key)) { temp = temp.next; if (EqualityComparer <T> .Default.Equals(temp.value, _tail.value)) { return(null); } } return(temp); }
public DirectionNode(T d) { value = d; prev = null; next = null; }