ProgrammingModerate
A doubly linked list stores prev pointers. How many pointer fields must change to insert a new node between two adjacent nodes A and B?
- A. 2
- B. 4
- C. 3
- D. 5
Correct answer: B. 4
new->prev and new->next are set, A->next and B->prev are redirected, so four pointers change.
More C Programming questions
- A singly linked list of N = 10^6 nodes must answer 10^6 queries for the value at position k. Which approach is correct and fast enough?
- A function frees an entire list and then sets head = NULL. Why is setting head to NULL useful?
- Which kind of list makes it O(1) to delete a node given only a pointer to that node?
- In a singly linked list, which operation takes O(1) time when a pointer to the head is given?
- Two pointers walk a linked list: fast goes two nodes per step, slow goes one. The list has an even number of nodes N = 8 and no cycle…
- A cyclic list has a head node whose next points back to itself. What does a naive while (p) loop starting from head do?