public void AddLast(T data) { var node = new DoublyNode <T>(data); if (head == null) { head = node; } else { tail.Next = node; node.Previous = tail; } tail = node; count++; }
public void AddFirst(T data) { var node = new DoublyNode <T>(data); var temp = head; node.Next = temp; head = node; if (count == 0) { tail = head; } else { temp.Previous = node; } count++; }
public T RemoveLast() { if (count == 0) { throw new InvalidOperationException(); } T output = tail.Data; if (count == 1) { head = tail = null; } else { tail = tail.Previous; tail.Next = null; } count--; return(output); }
public T RemoveFirst() { if (count == 0) { throw new InvalidOperationException(); } T output = head.Data; if (count == 1) { head = tail = null; } else { head = head.Next; head.Previous = null; } count--; return(output); }
public void Clear() { head = null; tail = null; count = 0; }