Beispiel #1
0
        public static void ReverseLinkedList(ref LinkedNode head)
        {
            LinkedNode previousNode = null;

            while (head != null)
            {
                LinkedNode nextNode = head.Next;
                head.Next    = previousNode;
                previousNode = head;
                head         = nextNode;
            }
            head = previousNode;
        }
Beispiel #2
0
        private static void ReverseLinkedListRecursive(ref LinkedNode head, LinkedNode current)
        {
            if (current == null)
            {
                return;
            }

            LinkedNode nextNode = current.Next;

            current.Next = head;
            head         = current;

            ReverseLinkedListRecursive(ref head, nextNode);
        }