Francisco Quintero
Feb 24, 2017 · 1 min read

I couldn’t understand what could go wrong when doing insertion of a new node in a bad order.

1: Add new node.

2: Add reference in new node to first node in the list.

3: Change head reference from first node to new node.

Changing 2 with 3 would give me:

1: Add new node.

2: Change head reference from first node to new node.

3: Add reference in new node to first node in the list.

I’m unable to see the problem because the pointer to the next node in first node would still point either to null or the next node in the list.

Is there something I’m not seeing?

Anyway, nice article!

    Francisco Quintero

    Written by

    Ingeniero de Software. https://www.franciscoquintero.com/

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight.
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox.
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month.