private static DoublyLinkedList InsertDoublyNodeAtFirstPosition(DoublyLinkedList dll)
        {
            var node = new DoublyNode();

            node.Value        = 100;
            node.Previous     = null;
            node.Next         = dll.Head;
            dll.Head.Previous = node;
            dll.Head          = node;

            return(dll);
        }
        private static DoublyLinkedList InsertNodeAtFirstPosition(DoublyLinkedList dll)
        {
            var node = new DoublyNode();

            node.Value = 100;
            var head = dll.Head;
            var pointerToLastNode = head.Previous;

            node.Next              = head;
            head.Previous          = node;
            node.Previous          = pointerToLastNode;
            pointerToLastNode.Next = node;

            dll.Head = node;
            return(dll);
        }
Beispiel #3
0
        public static DoublyLinkedList CreateDoublyLinkedList(int[] numArray)
        {
            var dll  = new DoublyLinkedList(numArray.Length);
            var node = new DoublyNode();

            node.Value    = numArray[0];
            node.Previous = null;
            node.Next     = null;
            dll.Head      = node;
            dll.Tail      = node;

            for (int i = 1; i < numArray.Length; i++)
            {
                var temp = new DoublyNode();
                temp.Value    = numArray[i];
                temp.Next     = null;
                temp.Previous = dll.Tail;
                dll.Tail.Next = temp;
                dll.Tail      = temp;
            }

            return(dll);
        }
        private static DoublyLinkedList InsertDoublyNodeAtNPosition(DoublyLinkedList dll, int position)
        {
            var node = new DoublyNode();

            node.Value = 500;

            var temp = dll.Head;

            for (int i = 1; i < position - 1; i++)
            {
                temp = temp.Next;
            }

            //var nodeToDelete = temp.Next;
            node.Previous = temp;
            node.Next     = temp.Next;
            temp.Next     = node;
            if (node.Next != null)
            {
                node.Next.Previous = node;
            }

            return(dll);
        }