ProgrammingHard
Reversing the list 1 -> 2 -> 3 -> 4 -> 5 in place with the usual three-pointer loop, what are head->v and head->next->v afterwards?
- A. 5 and 4
- B. 1 and 2
- C. 5 and 1
- D. 4 and 3
Correct answer: A. 5 and 4
After reversal the old tail 5 becomes the head and 4 follows it. The loop saves next before redirecting each pointer, so no node is lost.
More C Programming questions
- In a list 1 -> 2 -> 3 -> 4 -> 2 where the last node points back to the node holding 2, Floyd's method runs slow = slow->next and fast =…
- A pointer-to-pointer loop deletes every node holding 2 from 2 -> 2 -> 3 -> 2 -> 1, using struct N pp = &head and advancing only when no…
- Which code correctly removes node p from a doubly linked list, where p->prev and p->next may be NULL, and then frees it?
- Merging two sorted singly linked lists of length 3 each with the standard merge, what is the largest number of key comparisons needed?
- With a 4-byte int and an 8-byte pointer, natural alignment, what is sizeof(struct N) for struct N { int v; struct N next; };?
- A linked list is built by appending n nodes one by one, each time walking from the head to the last node. About how many node visits does…