ProgrammingModerate
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 value is returned by the last dequeue?
- A. 3
- B. 2
- C. 4
- D. 1
Correct answer: A. 3
The first two dequeues return 1 and 2. The last dequeue returns the oldest remaining value, which is 3.
More C Programming questions
- Which loop correctly frees every node of a singly linked list whose head is p?
- A recursive function prints a list after its recursive call returns, as in print(n) { if (!n) return; print(n->next); putchar(n->v + '0')…
- In a 6-node list with values 10, 20, 30, 40, 50, 60, the standard slow and fast pointer method (slow moves one step, fast two steps, while…
- Which operation removes the k-th node (1-based) from a singly linked list in one pass with a pointer to the previous node, and handles…
- Which realloc pattern does not leak memory or lose the original block if the reallocation fails?
- A dynamic array doubles its capacity whenever it is full. Pushing N = 10^6 values costs about how many element copies in total?