Exemple #1
0
        public DoubleLinkedListNode <T> Search(T value)
        {
            DoubleLinkedListNode <T> current = Head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    return(current);
                }

                current = current.Next;
            }

            return(null);
        }
Exemple #2
0
        public DoubleLinkedList <T> Add(T value)
        {
            if (Head == null)
            {
                Tail = Head = new DoubleLinkedListNode <T>(value);
            }
            else
            {
                var newNode = new DoubleLinkedListNode <T>(value);

                newNode.Previous = Tail;

                Tail = Tail.Next = newNode;
            }

            return(this);
        }
Exemple #3
0
        public DoubleLinkedList <T> Remove(T value)
        {
            DoubleLinkedListNode <T> current = Head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    if (current.Previous != null)
                    {
                        current.Previous.Next = current.Next;
                    }

                    if (current.Next != null)
                    {
                        current.Next.Previous = current.Previous;
                    }
                }

                current = current.Next;
            }

            return(this);
        }