Suite101
Post this Blog to facebook Add this Blog to del.icio.us! Digg this Blog furl this Blog Add this Blog to Reddit Add this Blog to Technorati Add this Blog to Newsvine Add this Blog to Windows Live Add this Blog to Yahoo Add this Blog to StumbleUpon Add this Blog to BlinkLists Add this Blog to Spurl Add this Blog to Google Add this Blog to Ask Add this Blog to Squidoo

Apr 13, 2007

C List Management Tutorials

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 head
  • A tail
  • A current node (in focus)

A node has:

  • Data
  • A pointer to the next node
  • A pointer to the previous node (possibly)

A new list has the following features:

  • The Head will be NULL
  • The Tail will be NULL
  • There is no Current node

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!)