ProgrammingHard
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 deletion happens. How many nodes remain?
- A. 1
- B. 3
- C. 2
- D. 4
Correct answer: C. 2
The three 2s are removed and the 3 and 1 stay. The pointer-to-pointer form needs no special case for the head node.
More C Programming questions
- 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…
- A stack is implemented with a singly linked list, pushing at the head. The operations are push 1, push 2, pop, push 3, push 4, pop, pop…
- A queue is kept as a singly linked list with head and tail pointers. Enqueue 1, 2, 3, dequeue twice, enqueue 4, then dequeue once. Which…