///<summary>Insert element at the begining of the list</summary> ///<param name="value">Value to insert</param> public override void Prepend(T value) { size++; DLListNode <T> newNode = new DLListNode <T>(value, beforeHeadNode, beforeHeadNode.Next); beforeHeadNode.SetNext(newNode); beforeHeadNode.Next.SetPrevious(newNode); }
///<summary>Insert element at the end of the list</summary> ///<param name="value">Value to append</param> public override void Append(T value) { size++; DLListNode <T> after = afterEndNode.Previous; DLListNode <T> newNode = new DLListNode <T>(value, after, afterEndNode); after.SetNext(newNode); afterEndNode.SetPrevious(newNode); }
///<summary>Creates new instance of <see cref="DLList{T}"></summary> public DLList() { this.size = 0; this.beforeHeadNode = new DLListNode <T>(default(T), null, afterEndNode); this.afterEndNode = new DLListNode <T>(default(T), beforeHeadNode, null); //its little tricky, prev and after always points to itself //this will help in IEnumerator implementation in DLListIterator class beforeHeadNode.SetPrevious(beforeHeadNode); beforeHeadNode.SetNext(afterEndNode); afterEndNode.SetNext(afterEndNode); afterEndNode.SetPrevious(beforeHeadNode); }
public override void Remove(T value) { DLListIterator <T> toRemoveIterator; int index = GetIndexOf(value, out toRemoveIterator); if (index > -1) { DLListNode <T> toDelete = toRemoveIterator.GetCurrentNode(); toDelete.Previous.SetNext(toDelete.Next); toDelete.Next.SetPrevious(toDelete.Previous); //remove references toDelete.SetNext(null); toDelete.SetPrevious(null); } }
public void SetPrevious(DLListNode <T> previousNode) { this.Previous = previousNode; }
public void SetNext(DLListNode <T> nextNode) { this.Next = nextNode; }
public DLListNode(T value, DLListNode <T> previous, DLListNode <T> next) { this.Value = value; this.Previous = previous; this.Next = next; }
public void Reset() { this.current = beforeHeadNode; }
public bool MovePrevious() { current = current.Previous; return(current != beforeHeadNode); }
public bool MoveNext() { current = current.Next; return(current != afterEndNode); }
public DLListIterator(DLListNode <T> beforeHeadNode, DLListNode <T> afterEndNode) { this.beforeHeadNode = beforeHeadNode; this.afterEndNode = afterEndNode; this.current = beforeHeadNode; }