示例#1
0
        public bool Contains(T data)
        {
            DoublyNode <T> current = head;

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

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

            if (head == null)
            {
                head = node;
            }
            else
            {
                tail.Next     = node;
                node.Previous = tail;
            }
            tail = node;
            count++;
        }
        public bool Contains(T data)
        {
            DoublyNode <T> node = Head;

            while (node != null)
            {
                if (node.Data.Equals(data))
                {
                    return(true);
                }

                node = node.Next;
            }

            return(false);
        }
示例#4
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++;
        }
示例#5
0
        public void Add(T data)
        {
            DoublyNode <T> item = new DoublyNode <T>(data);

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

            count++;
        }
示例#6
0
        public void AppendFirst(T item)
        {
            DoublyNode <T> data = new DoublyNode <T>(item);

            if (head != null)
            {
                head.Previous = data;
                data.Next     = head;
                head          = data;
            }
            else
            {
                head = data;
                tail = data;
            }
            count++;
        }
示例#7
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
                    tail = current.Previous;
                }

                // если узел не первый
                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    // если первый, переустанавливаем head
                    head = current.Next;
                }
                count--;
                return(true);
            }
            return(false);
        }
        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;
                }

                if (current.Previous != null)
                {
                    current.Previous.Next = current.Next;
                }
                else
                {
                    Head = current.Next;
                }
                count--;

                return(true);
            }

            return(false);
        }
示例#9
0
        public bool Remove(T data)
        {
            DoublyNode <T> current  = head;
            DoublyNode <T> previous = null;

            DoublyNode <T> item = new DoublyNode <T>(data);

            while (current != null)
            {
                if (current.Data.Equals(item.Data))
                {
                    if (previous == null)
                    {
                        head          = head.Next;
                        head.Previous = null;
                    }
                    else
                    {
                        if (current.Next == null)
                        {
                            tail = previous;
                        }
                        else
                        {
                            current.Next.Previous = previous;
                        }
                        previous.Next = current.Next;
                    }
                    count--;
                    return(true);
                }
                else
                {
                    previous = current;
                    current  = current.Next;
                }
            }
            return(false);
        }
示例#10
0
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
 }
 public void Clear()
 {
     Head  = null;
     Tail  = null;
     count = 0;
 }