title: Segmentation fault in NULL check?
body: <p>I am getting a segmentation fault while trying to check if some elements are <code>NULL</code> or not. Can anyone help?</p>
  
  <pre><code>    void addEdge(int i, int j) 
  {
          if (i &gt;= 0 &amp;&amp; j &gt; 0) 
      {
          Node* whereto;
          whereto = linkedAdjacencyList[i];
          if(whereto != NULL)
          {
              while(whereto-&gt;adj != NULL)
              {whereto = whereto-&gt;adj;}
              whereto-&gt;adj = linkedAdjacencyList[j];
          }
          else{linkedAdjacencyList[i]-&gt;adj = linkedAdjacencyList[j];}
          whereto = linkedAdjacencyList[j];
          if(whereto != NULL)
          {
              while(whereto-&gt;adj != NULL)
              {whereto = whereto-&gt;adj;}
              whereto-&gt;adj = linkedAdjacencyList[i];
          }
          else{linkedAdjacencyList[j]-&gt;adj = linkedAdjacencyList[i];}
              }
      }
  </code></pre>
  
  <p>help!</p>
  
  <p>EDIT: this is the new code, as per your suggestions, but now there is a segmentation fault immediately when the method is called? i'll post the calling...</p>
  
  <pre><code>int edges;
  in &gt;&gt; edges;
  g.edges = edges;
  for(int i = 0; i &lt; edges; i++)
  {
      int first;
      int second;
      in &gt;&gt; first &gt;&gt; second;
      g.addEdge(first, second);
  }
  </code></pre>