DEV Community

TobyMike-max
TobyMike-max

Posted on

Linked Lists in C

The idea behind linked list is about moving creating node-pointers to store addresses, moving addresses to node-pointers declared individually or node-pointers contained in a node.
Understanding the process and being able to relate with it in real life situations makes understanding better.

To understand the concept of linked lists think of a chain of paper clips all connected together.
Paper Clip Description
The basic operation performed on a linked list can be seen in the following ways:

  1. Creating a chain of paper clips (or a linked list) is done by connecting each paper clip end to end until you choose to stop.

  2. To add a paper clip in the middle of a chain of paper clips you'll have to break the connection, keep the second half of the chain somewhere, connect the new paper clip to the other half of the chain, then connect the second half of the chain that was kept away to the end of the newly connected paper clip.

  3. Removing a paper clip (or a node) follows a similar simple process. Locate the point of paper clip tat needs to be removed. Split the chain of paper clips from that point but don't forget to always store the second half of the chain somewhere [like a temp variable :)]. Follow the same procedure as above and you're good to go.

Implementing the code for the above can now be easily done. Good luck :)

Top comments (0)