Thread: how to implement SPARSE graph in c/c++?

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    19

    how to implement SPARSE graph in c/c++?

    i want to implement sparse graph in c\c++.

    i need help regarding it.
    is there any builtin sparse graph in STL?
    or any kind of help that STL can provide regarding this?

    any help will be highly appreciated.

    :-)
    C/C++ IDE: Microsoft visual studio .Net 2003

    Wisdom is the reward for a lifetime of listening... when you'd have preferred to talk.

  2. #2
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    is there any builtin sparse graph in STL?
    Not as such, but you can build one easily with the standard containers:
    Code:
    #include <iostream>
    #include <list>
    #include <vector>
    
    using namespace std;
    
    int main() {
      vector< list<int> > graph(7);
    
      /*
      Make this directed graph:
      
      4 ------------->------+->-+
      ^                     |   |
      |                     |   |
      5 ----->------+-> 6 <-+   |
                    ^   |       |
                    |   |       |
      0 ---> 1 ---> 2 --+-> 3 <-+
      ^      ^              |
      |      +-------<------+
      |                     |
      +----------<----------+
      */
      graph[0].push_back(1);
      graph[1].push_back(2);
      graph[2].push_back(3); graph[2].push_back(6);
      graph[3].push_back(0); graph[3].push_back(1);
      graph[4].push_back(3); graph[4].push_back(6);
      graph[5].push_back(4); graph[5].push_back(6);
      graph[6].push_back(3);
    
      return 0;
    }
    Just because I don't care doesn't mean I don't understand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Graph -adjacency linked list
    By dpp in forum C++ Programming
    Replies: 7
    Last Post: 12-01-2009, 09:49 AM
  2. error help making no sense
    By tunerfreak in forum C++ Programming
    Replies: 5
    Last Post: 04-17-2007, 07:55 PM
  3. Help w/ graph as adjacency matrix
    By ac251404 in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2006, 10:25 PM
  4. determining a path through the graph
    By Mist in forum C Programming
    Replies: 2
    Last Post: 02-27-2005, 12:21 PM
  5. Minimize crossing edges in undirected graph
    By Shiro in forum C Programming
    Replies: 0
    Last Post: 12-26-2001, 04:48 AM