public void Insert(T value, int pos) { MyDoublyNode <T> node = new MyDoublyNode <T>(value); if (pos == 0) { node.Next = first; first = node; if (last == null) { last = node; } } else { MyDoublyNode <T> tmp = first; for (int i = 0; i < pos - 1; i++) { tmp = tmp.Next; } node.Next = tmp.Next; node.Prev = tmp.Prev; tmp.Next = node; } count++; }
public int IndexOf(T value) { MyDoublyNode <T> tmp = first; int i = 0; while (!tmp.Value.Equals(value) && tmp != null) { tmp = tmp.Next; i++; } return(i); }
public void AddFirst(T value) { MyDoublyNode <T> node = new MyDoublyNode <T>(value); if (first == null) { first = node; last = node; } else { node.Next = first; first = node; } count++; }
public MyDoublyNode <T> Find(int index) { if (index > count - 1) { return(null); } MyDoublyNode <T> tmp = first; int i = 0; while (index != i) { tmp = tmp.Next; i++; } return(tmp); }
public void AddLast(T value) { MyDoublyNode <T> node = new MyDoublyNode <T>(value); if (first == null) { first = node; last = node; } else { last.Next = node; node.Prev = last; last = node; } count++; }
public void Clear() { first = null; last = null; count = 0; }