Thread: Need advise on adjency list

  1. #1
    Brak BoneXXX's Avatar
    Join Date
    Mar 2007
    Location
    Bangkok
    Posts
    62

    Need advise on adjency list

    Hi all,

    I need some advise about the program that I am going to write. I'll try to explain it briefly. There is going to be an array, such as ;

    [ 0 1 2 3 4 5 6]

    and each array element going to have a link list(separate link lists).

    My first question is; is that possible?If it is, could you explain it briefly with a simple language?If it is not possible, what alternatives do I have?

    The image that I added is a example of what I want to do.

    Thanks from now.
    “Example isn't another way to teach, it is the only way to teach” Albert Einstein

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So it's an array of linked list pointers.

    Code:
    struct llTag {
      int payload;
      struct llTag *next;
    };
    
    struct llTag *adjacency[7] = { 0 };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    If it only goes upto 7 then yes, otherwise a linked list of linked list pointers.

  4. #4
    Brak BoneXXX's Avatar
    Join Date
    Mar 2007
    Location
    Bangkok
    Posts
    62
    Thanks for the replies. I will try to give more information about the question that I am going to solve. The user will specify the number of vertices. For example: 7.

    In the numerical order of verices(0-1-2...7), the user is going to declare the number of out going edges, then vertex number + edge weight. After getting these information, the program going to find the shortest path distances.

    I thought I can create a array by the number of vertices from the user as a input and create separate link lists for each element of the array.Then after that I can find the shortest path.

    So this is the question and the idea that I have to solve. If you could give me some hints I would really appreciate it.
    Last edited by BoneXXX; 05-22-2007 at 10:44 PM.
    “Example isn't another way to teach, it is the only way to teach” Albert Einstein

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Seems like you have the right idea - go for it
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 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. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM