1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Rep Power

    A tutorial for double linked lists?

    Hi - I decided to learn a better perspective of binary trees later on in the weekend. But during the week I want to try to attempt doubly linked lists. Shouldn't be so hard, right? I understand linked lists fine so I don't think double linked lists should be no jiffy.

    I'm already thinking the structure should be this:
    typedef struct doubly {
    	int val;
    	struct doubly *next;
    	struct doubly *previous;
    } doubly;
    But, like my brain always works, I'm not sure how I can put this in use. So I'm asking, can someone send me an accurate link to a good tutorial? I tried looking it up on google but all I found was examples and no explanations to those examples.

    That'll be great. Like I said, this shouldn't be any more complex to understand. So just getting a tutorial on the webs would be great. thanks
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    This author feels the same way you do and did something about it.

    I draw linked lists on paper. Then given some access node I decide if I'll work to the "next" or "previous" side, and I circle or mark the pointers I need to change for an insertion or deletion, figure out the order these need to happen (including decisions about malloc and free). Then write the code to match. So for a doubly linked list there are usually 4 pointers you need to change. As always you need to also consider the end cases. What happens with no nodes, one node, two nodes, three nodes---after that I'm pretty sure you're all set.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo