public void PrintAllElements() { DequeTNode <T> toPrint = new DequeTNode <T> { Value = _head.Value }; toPrint.Next = _head.Next; Console.Write($"{toPrint.Value} "); while (toPrint.Next != null) { toPrint.Value = toPrint.Next.Value; Console.Write($"{toPrint.Value} "); toPrint.Next = toPrint.Next.Next; } Console.WriteLine(); }
public void PushBack(T element) { DequeTNode <T> next = new DequeTNode <T> { Value = element }; if (_head == null) { _head = next; } else { _tail.Next = next; next.Previous = _tail; } _tail = next; _count++; }
public void PushFront(T element) { DequeTNode <T> previous = new DequeTNode <T> { Value = element }; if (_head == null) { _head = previous; _tail = _head; } else { previous.Next = _head; _head.Previous = previous; _head = previous; } _count++; }
public T PopFront() { if (_count == 0) { throw new ArgumentOutOfRangeException("The deque is empty"); } T toReturn = _head.Value; if (_count == 1) { _head = null; _tail = null; } else { _head = _head.Next; _head.Previous = null; } _count--; return(toReturn); }