public void Remove() { this.myEnumerator.SetInvalid(); if (null != this.cursor) { DLNode <T> old = this.cursor; if (this.cursor == this.head) { this.head = this.cursor.Next; } if (this.cursor == this.tail) { this.tail = this.cursor.Prev; } if (null != this.cursor.Next) { this.cursor.Next.Prev = this.cursor.Prev; } if (null != this.cursor.Prev) { this.cursor.Prev.Next = this.cursor.Next; } if (null != this.cursor.Next) { this.cursor = this.cursor.Next; } else { this.cursor = this.cursor.Prev; } Delete(old); } }
public void AddAfter(T item) { this.myEnumerator.SetInvalid(); DLNode <T> node = New(item); if (null == this.tail) { this.tail = node; this.head = node; this.cursor = node; } else if (this.cursor == this.tail) // neither tail nor cursor are null { this.tail = node; node.Prev = this.cursor; node.Prev.Next = node; this.cursor = node; // we set the cursor ti the inserted node } else { node.Next = this.cursor.Next; node.Prev = this.cursor; node.Next.Prev = node; node.Prev.Next = node; this.cursor = node; // we set the cursor to the inserted node } }
public bool MoveNext() { if (null == this.current) { this.current = this.root; } else { this.current = this.current.Next; } return(null != this.current); }
public void MoveCursorPrev() { if (null != this.cursor) { if (null != this.cursor.Prev) { this.cursor = this.cursor.Prev; } } else { cursor = this.head; } }
public void MoveCursorNext() { if (null != this.cursor) { if (null != this.cursor.Next) { this.cursor = this.cursor.Next; } } else { cursor = this.tail; } }
private static void freeMemory() { DLNode <T> current = avail; DLNode <T> next = avail; while (null != current) { next = current.Next; current.Item = null; current.Prev = null; current.Next = null; current = next; } avail = null; }
private static DLNode <T> New(T item) { DLNode <T> result = null; if (null != avail) { result = avail; avail = avail.Next; result.Prev = null; result.Next = null; result.Item = item; } else { result = new DLNode <T>(item); } return(result); }
public void SetValid(DLNode <M> start) { this.root = start; }
private static void Delete(DLNode <T> node) { node.Item = null; node.Next = avail; avail = node; }