Graph with incidence lists (problem)

This is a discussion on Graph with incidence lists (problem) within the C++ Programming forums, part of the General Programming Boards category; Hello everybody, I would link to represent a graph with incidence lists. This picture is what I've thought about : ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    Graph with incidence lists (problem)

    Hello everybody,

    I would link to represent a graph with incidence lists.

    This picture is what I've thought about:

    http://img697.imageshack.us/img697/2640/incidence.jpg

    This is what I created:

    Code:
    #include <cstdlib>
    #include <iostream>
    It seems to work but when I insert more than one edge to a vertex the new edge overwrites the first one, so I can just have an edge per vertex...

    Can you help...?
    Thanks!
    Last edited by ferenczi; 05-25-2010 at 02:35 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    When you walk through loc01->inclist, you're really moving the pointer inside the object, thus walking that "head" pointer through your other edges, making the rest just go away. You'll wanto to (a) use a temporary pointer to do that walking and (b) not forget to hook the new edge on the end of the list, which you aren't doing yet either.

    Also you are leaking your entire memory, so you'll want to come up with a mechanism for returning all that memory. Or, better yet, just use <list>.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Lists? Is it possible? Is it a logical solution?
    By arcaine01 in forum C++ Programming
    Replies: 10
    Last Post: 07-23-2009, 02:08 AM
  2. intersection of two STL lists
    By misterMatt in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2009, 01:25 AM
  3. Lists for producer/consumer problem
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2009, 01:57 PM
  4. Graph problem time limit
    By dpp in forum C++ Programming
    Replies: 2
    Last Post: 01-15-2009, 05:13 PM
  5. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 06:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21