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

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

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

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

                current = current.Next;
            }
        }
Exemplo n.º 3
0
        public bool Contains(T data)
        {
            DoubleNode <T> current = head;

            while (current != null)
            {
                if (current.data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
Exemplo n.º 4
0
        public void Output()
        {
            if (IsEmpty)
            {
                Console.Write("Empty");
            }
            DoubleNode <T> node = head;

            while (node != null)
            {
                Console.Write("{0} ", node.data);
                node = node.Next;
            }
            Console.Write('\n');
        }
Exemplo n.º 5
0
        int count;           // количество элементов в списке

        // добавление элемента
        public void Add(T data)
        {
            DoubleNode <T> node = new DoubleNode <T>(data);

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
Exemplo n.º 6
0
        public void AddFirst(T data)
        {
            DoubleNode <T> node = new DoubleNode <T>(data);
            DoubleNode <T> temp = head;

            node.Next = temp;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            else
            {
                temp.Previous = node;
            }
            count++;
        }
Exemplo n.º 7
0
        // удаление
        public bool Remove(T data)
        {
            DoubleNode <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
                    tail = current.Previous;
                }

                // если узел не первый
                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    // если первый, переустанавливаем head
                    head = current.Next;
                }
                count--;
                return(true);
            }
            return(false);
        }
Exemplo n.º 8
0
 public int CompareTo(DoubleNode <T> other)
 {
     return(data.CompareTo(other.data));
 }
Exemplo n.º 9
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }