← Back to Pointers
Question 470
Reverse a Singly Linked List In Place
Reverse a Singly Linked List In Place
Read an integern, thennmore 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'snextpointer — 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 — 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.