Ejemplo n.º 1
0
        public static void ReverseDoubleLinkedList(ref DoubleLinkedNode head)
        {
            DoubleLinkedNode previousNode = null;

            while (head != null)
            {
                DoubleLinkedNode nextNode = head.Next;
                head.Previous = head.Next;
                head.Next     = previousNode;
                previousNode  = head;
                head          = nextNode;
            }
            head = previousNode;
        }
Ejemplo n.º 2
0
        private static void ReverseDoubleLinkedListRecursive(ref DoubleLinkedNode head, DoubleLinkedNode currentNode)
        {
            if (currentNode == null)
            {
                return;
            }

            DoubleLinkedNode nextNode = currentNode.Next;

            currentNode.Previous = currentNode.Next;
            currentNode.Next     = head;
            head = currentNode;

            ReverseDoubleLinkedListRecursive(ref head, nextNode);
        }