Thread: What is double-linked list?

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    What is double-linked list?

    Hi,

    i know linked lists. But what are double-linked lists?

    thnxq

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    a linked list that can go backwards as well as forwards and requires an extra pointer or two to acheive this....although i have never used it so far.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    That is correct, In a singly linked list you only point in one direction, where the doubly linked list points to nodes before and after itself. Which makes insertion into a list a little easier
    Code:
    typedef struct node NODE;
    
    /* Node for a singly linked list */
    struct node
    {
      int  data;
      NODE *next;
    };
    
    /* Node for a doubly linked list */
    struct node 
    {
      int  data;
      NODE *prior;
      NODE *next;
    };
    Last edited by foniks munkee; 04-15-2002 at 08:03 PM.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    it also makes it a lot easier and quicker to free up memory on a large scale, like when you quit your program, you can simply do somethin like:
    Code:
    while(tempptr->next != NULL)
    {
      tempptr=tempptr->next;
      free(tempptr->prev);
    }
    free(tempptr);
    only disadvantage of double linked lists is the extra memory it uses and the extra few instructions needed to add items into the list but quiet often you'll find that its worth it for the convenience.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Double Linked List Problem
    By Shiggins in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2009, 07:15 AM
  2. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM