Reverse a Singly Linked List In Place
hardQuestion 470Read an integer n, then n more integers, and build a singly linked list holding those values in the order they were read (the first value read is the head). Print the list, then reverse it IN PLACE by re-pointing each node's next pointer — do not build a second list and do not copy values between nodes. Print the reversed list, then free it.
For the input:
4 4 1 7 2
the program prints exactly the output shown in Expected Output.
Format: each line is the label, a colon, and then a space before every value. Nothing follows the last value.
Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected output
Original: 4 1 7 2 Reversed: 2 7 1 4
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.