public IEnumerable <T> BackEnumerator() { DoublyNode <T> current = tail; while (current != null) { yield return(current.Data); current = current.Previous; } }
IEnumerator <T> IEnumerable <T> .GetEnumerator() { DoublyNode <T> current = head; while (current != null) { yield return(current.Data); current = current.Next; } }
// Удаление из начала очереди public T popFront() { if (size == 0) { throw new InvalidOperationException(); } T output = head.Data; head = head.Next; size--; return(output); }
// Удаление из конца очереди public T popBack() { if (size == 0) { throw new InvalidOperationException(); } T output = tail.Data; tail = tail.Previous; tail.Next = null; size--; return(output); }
private DoublyNode <T> tail; // последний/хвостовой элемент // Добавление элемента в конец public void pushBack(T data) { DoublyNode <T> node = new DoublyNode <T>(data); if (head == null) { head = node; } else { tail.Next = node; node.Previous = tail; } tail = node; size++; }
// Добавление элемента в начало public void pushFront(T data) { DoublyNode <T> node = new DoublyNode <T>(data); DoublyNode <T> temp = head; node.Next = temp; head = node; if (size == 0) { tail = head; } else { temp.Previous = node; } size++; }
// Очищение очереди public void Clear() { head = null; tail = null; size = 0; }