Linked List Reversal

Linked list reversal: reversing a linked list in place with three references, and reversing part of a list or groups of nodes with a dummy node.

  • 8 cards
  • 4 questions
  • About 18 min
  • Intermediate to Advanced
Share

Linked list reversal turns every next reference of a list round in one pass, using three references, prev, curr and next, and four lines in a fixed order. It matters because reordering a linked list, or reading it backwards, is otherwise a copy into an array or a walk to the end for every node, and because getting the four lines in the wrong order loses the rest of the list without an error. The topic shows the four lines one node at a time, derives them from a brute force that walks to the end again and again, and gives the template in three languages. It reverses one stretch of a list with a dummy node, checks whether a word stored as a list reads the same backwards, shows what happens when the arrow is flipped before it is saved, and ends with an exercise that reverses a boarding queue in groups of three.

Contents

8 cardsnot started