Exemplo n.º 1
0
        public void InsertAtFront <T>(DoublyLinkedList <T> list, T data)
        {
            DoublyNode <T> newNode = new DoublyNode <T>(data);

            newNode.Next     = list.Head;
            newNode.Previous = null;
            if (list.Head != null)
            {
                list.Head.Previous = newNode;
            }
            list.Head = newNode;
        }
Exemplo n.º 2
0
        public void InsertAfter <T>(DoublyNode <T> prevNode, T data)
        {
            if (prevNode == null)
            {
                Console.WriteLine("given previous Data cannot be null");
                return;
            }
            DoublyNode <T> newNode = new DoublyNode <T>(data);

            newNode.Next     = prevNode.Next;
            prevNode.Next    = newNode;
            newNode.Previous = prevNode;
        }
Exemplo n.º 3
0
        public void ReverseList(DoublyLinkedList <T> list)
        {
            var            current      = list.Head;
            DoublyNode <T> previousNode = null;
            DoublyNode <T> nextNode;

            while (current.Next != null)
            {
                nextNode              = current.Next;
                current.Next          = previousNode;
                current.Next.Previous =
                    previousNode      = current;
                current = nextNode;
            }
        }