Beispiel #1
0
        public bool Contains(DoubleList data)
        {
            DoublyNode <DoubleList> current = head;

            while (current != null)
            {
                if (current.Data.Equals(data))
                {
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
Beispiel #2
0
        int count;                                                        // количество элементов в списке

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

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
Beispiel #3
0
        public void AddFirst(DoubleList data)
        {
            var node = new DoublyNode <DoubleList>(data);
            DoublyNode <DoubleList> temp = head;

            node.Next = temp;
            head      = node;
            if (count == 0)
            {
                tail = head;
            }
            else
            {
                temp.Previous = node;
            }
            count++;
        }
Beispiel #4
0
        // удаление
        public bool Remove(DoubleList data)
        {
            DoublyNode <DoubleList> 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);
        }
Beispiel #5
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }