ProgrammingModerate
A singly linked list of five nodes 1 -> 2 -> 3 -> 4 -> 5 has the node with value 3 unlinked and freed. How many nodes remain?
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: B. 4
Unlinking and freeing one node leaves 5 - 1 = 4 nodes; node 2 is simply relinked to node 4. 3 assumes a neighbour is freed too, and 2 confuses unlinking node 3 with truncating the list there.
More C Programming questions
- Deleting a node from the middle of a doubly linked list of length n costs what, if a pointer to the node is already known?
- A chained table with 10 buckets holds 30 keys. What is the average chain length?
- A dynamic array grows from capacity 1 by doubling. How many doublings are needed to reach capacity 1024 from 1?
- A list of 6 nodes is split into two halves by a slow and fast pointer. The slow pointer is at the start of the second half. Which node…
- A stack is kept as a linked list with the top at the head. Push A, push B, pop, push C, pop. Which element is on top at the end?
- A queue made from a singly linked list with a head and a tail pointer enqueues 1, 2 and 3, then dequeues once. What is the front value now?