Thread: implementing graph using linked list

  1. #1
    Tim
    Guest

    Unhappy implementing graph using linked list

    Anybody knows how can I implement graph using linked list? I get the idea at the abstract level, and I know how to do it using arrays, but I don't know how to write the code using linked list.

    I'd really appreciate it.
    Thanks

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    6
    You would need to use a linked list for each node. The linked lists are used to store the edges that connect from the node in question to another node.

    The simplest way to store the nodes would be in an array, unless of cause you need to be flexible and then you would also use a linked list to store the nodes.

    The following structure variables should be a start:

    struct NODE_S
    {
    struct LINKED_LIST_S *edges;
    };

    struct LINKED_LIST_S
    {
    int node;
    struct LINKED_LIST_S *next;
    };

    struct NODE_S nodeArray[??];


    I would also suggest the following functions as a start:

    /* simply add the node to the array of nodes */
    int add_node ()

    /* add an item to the linked list for this node */
    int add_node_edge ()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Linked List
    By jpipitone in forum C Programming
    Replies: 4
    Last Post: 03-30-2003, 09:27 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM