graph using adjacency list - problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • orzeech
    New Member
    • Nov 2008
    • 5

    graph using adjacency list - problem

    Here's my code that's supposed to be a basic graph implementation using adjacency lists. It comes straight from R.Sedgewick's "Algorithms in C++".
    However "23 - ISO C++ forbids declaration of `vector' with no type ". Why is that?


    Code:
    class graf
    {
    
        struct edge
    {
           int v, w;
           edge(int v = -1, int w = -1) : v(v), w(w) {}
    };
    
    struct node
                  {
                         int v; node* next;
                         node(int x, node* t) {v = x; next = t; }
                  };
         
          typedef node* link;
          vector <link> adj;
                             
         
          
    public:
                 graf(int V) : adj(V) {adj.assign(V,0);}
                 int insert(edge e)
                 {
                     int v = e.v, w=e.w;
                     adj[v] = new node(w, adj[v]);
                     adj[w] = new node(v, adj[w]);
                     } 
                 void remove(edge e);
                 bool edge(int v,int w) const;
                 class adjIterator;
                 friend class adjIterator;
    };
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    Do you have
    Code:
    #include <vector>
    using namespace std;
    and the top of your header file?

    Comment

    • orzeech
      New Member
      • Nov 2008
      • 5

      #3
      Originally posted by boxfish
      Do you have
      Code:
      #include <vector>
      using namespace std;
      and the top of your header file?

      I forgot about it... Thank you again!

      Comment

      Working...