title: Graphs using Adjacency List in c++
body: <p>I am trying to implement a graph in C++. I am representing a node in graph using a structure which contains two variables - <br />a) an integer to contain some information about the node. <br />b) a list to contain index of other vertex which are connected to it. <br />Following is the code. </p>
  
  <pre><code>// Graphs using adjacency list
  
  #include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  // structure to represent a vertex(node) in a graph
  typedef struct vertex{
      int info;
      list&lt;int&gt; adj;   // adjacency list of edges contains the indexes to vertex
  } *vPtr;             
  
  int main(){
      vPtr node = (vPtr)malloc(sizeof(struct vertex));
      node-&gt;info = 34;            // some arbitrary value
      (node-&gt;adj).push_back(2);   // trying to insert a value in the list
      return 0;
  }
  </code></pre>
  
  <p>The code is compiling fine but I am getting a run time error while I am pushing back an element in the list. Is there any problem in my structure. <br /> I am using code blocks and GNU GCC, C++ 98 compiler to compile my code. </p>