Exemplo n.º 1
0
        public IEnumerable <T> BackEnumerator()
        {
            DoublyNode <T> current = tail;

            while (current != null)
            {
                yield return(current.Data);

                current = current.Previous;
            }
        }
Exemplo n.º 2
0
        IEnumerator <T> IEnumerable <T> .GetEnumerator()
        {
            DoublyNode <T> current = head;

            while (current != null)
            {
                yield return(current.Data);

                current = current.Next;
            }
        }
Exemplo n.º 3
0
        // Удаление из начала очереди
        public T popFront()
        {
            if (size == 0)
            {
                throw new InvalidOperationException();
            }
            T output = head.Data;

            head = head.Next;
            size--;
            return(output);
        }
Exemplo n.º 4
0
        // Удаление из конца очереди
        public T popBack()
        {
            if (size == 0)
            {
                throw new InvalidOperationException();
            }
            T output = tail.Data;

            tail      = tail.Previous;
            tail.Next = null;
            size--;
            return(output);
        }
Exemplo n.º 5
0
        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++;
        }
Exemplo n.º 6
0
        // Добавление элемента в начало
        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++;
        }
Exemplo n.º 7
0
 // Очищение очереди
 public void Clear()
 {
     head = null;
     tail = null;
     size = 0;
 }