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; }
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); }