Bitpath

Lesson 2 · Unit 03

Insert and delete

The order of pointer updates, and the dummy head

13 exercisesabout 3 min

What you practise

  • Order of pointer updates
  • The dummy head trick

Try a question from this lesson

Pick one

In a chain, A points to B. To put X between them you must change two pointers. Which change has to come first?

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

A dummy node in front

The head is awkward because nothing points to it. So add something that does: a dummy node whose next is the real head.

Now every real node has a node before it, and one piece of code handles them all. When you finish, the list starts at dummy.next, which is correct even if the old head was deleted.

11 more exercises in the app

  • 1× order the lines
  • 3× type the answer
  • 4× multiple choice
  • 2× fill the blanks
  • 1× true or false

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy