Пример #1
0
        public IEnumerable <T> BackEnumerator()
        {
            DoublyNode <T> current = tail;

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

                current = current.Previous;
            }
        }
Пример #2
0
        IEnumerator <T> IEnumerable <T> .GetEnumerator()
        {
            DoublyNode <T> current = head;

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

                current = current.Next;
            }
        }
Пример #3
0
        public void AddFirst(T data)
        {
            DoublyNode <T> node = new DoublyNode <T>(data);
            DoublyNode <T> temp = head;

            node.Next = temp;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            else
            {
                temp.Previous = node;
            }
            count++;
        }
Пример #4
0
        public void AddLast(T data)
        {
            DoublyNode <T> node = new DoublyNode <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }

            tail = node;
            count++;
        }
Пример #5
0
        public bool Remove(T data)
        {
            DoublyNode <T> current = head;

            // поиск удаляемого узла
            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    break;
                }
                current = current.Next;
            }

            if (current != null)
            {
                // если узел не последний
                if (current.Next != null)
                {
                    current.Next.Previous = current.Previous;
                }
                else
                {
                    tail = current.Previous; // если последний, переустанавливаем tail
                }
                // если узел не первый
                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    head = current.Next; // если первый, переустанавливаем head
                }
                count--;
                return(true);
            }

            return(false);
        }
Пример #6
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }