Thread: Graph with incidence lists (problem)

  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 01:35 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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, 01:08 AM
  2. intersection of two STL lists
    By misterMatt in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2009, 12:25 AM
  3. Lists for producer/consumer problem
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2009, 12: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, 05:20 AM