|
|
Posted by Guy Lecky-Thompson Apr 13, 2007 |
List management in C programming scares some people, and it used to scare me. Really.
So, here are some resources to help you find a way through the tangle. All that you have to remember is that a list has:
A node has:
A new list has the following features:
So, to create a list, you just need to make sure that the first node is the Head and Tail and current. You can then add to either end just be re-pointing the pointer in the nodes. It's easy.
Sorting the list requires being able to swap nodes. And in case you're thinking that that is too tricky, and you want to stick everything in an array instead, then read the articles. Then decide which is the best approach for you. You might be pleasantly surprised!
The complete list is:
The first is the latest, and details how to swap data items, which is useful for creating and sorting lists. The third relates to everything required to manage a linked list in C, including pointers, adding to, removing from and sorting the list, and sandwiched between the two is a practical example.
Have fun!
(PS : If you have any questions, please post them as a discussion, and perhaps I can make a full Q&A or even a tutorial out of them!)