Data Structures & AlgorithmsVery hard
In iterative reversal of a singly linked list, which pointer must be saved BEFORE the current node's next pointer is changed?
- A. The head of the list.
- B. The original next pointer of the current node.
- C. The previous node's previous pointer.
- D. The tail of the list.
Correct answer: B. The original next pointer of the current node.
Re-pointing next overwrites the only link to the rest of the list, so the original next must be stored in a temporary variable first. Otherwise the remaining nodes become unreachable.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For sorted positive integers, the smallest value that cannot be formed as a subset sum equals R+1, where R is the reach. Why does a value…
- Items (weight, value) are [(5, 60), (4, 40), (6, 50), (3, 30), (2, 15), (7, 70)]. Each item can be taken at most once, and the total…
- A shop has these items as (weight, value, number available): [(2, 10, 2), (3, 14, 3), (5, 30, 1)]. You may take at most the listed number…
- How many subsets of [2, 3, 5, 7, 4, 1, 6, 8] (chosen by position, the empty set excluded) have a sum of exactly 10?
- The numbers [31, 26, 33, 21, 40] are split into two groups (every number goes to exactly one group). What is the smallest possible…
- Each number in [1, 2, 3, 4, 5, 6, 7] gets a sign '+' or '-', and all are then added. How many sign choices give a total of exactly 4?