AlgoFrames

Insert after a node

Warm-up · Trace the algorithm · about 4 min

Insert 99 after the node holding 5 in 3 → 8 → 5 → 1. Answer each question before the step plays.

Example 1

Input:

{"values":[3,8,5,1],"after":5,"value":99}

Output:

[3,8,5,99,1]

Constraints

  • The trace uses the list shown.

Learn the idea first: Singly linked lists: traverse, insert, delete, a visual lesson.

More Singly linked lists: traverse, insert, delete problems