title: Why is this segfaulting whilst building a binary tree?
body: <p>I have found this line in this code through gdb to be seg faulting. However I can't seem to see why? It will run through 6/7 times before a seg fault occurs. Temp is a node in a linked list which contains a frequency (int), which I use to find the place in an ascending linked list to insert a new node.</p>
  
  <pre><code>while (ind == 0 &amp;&amp; temp != NULL)
  {
      temp = temp -&gt; next;
      if (temp -&gt; frequency &gt; parent_node -&gt; frequency) /*&lt;--- SEG FAULT HERE */
      {
          parent_node -&gt; next = temp -&gt; next; /* parent points at higher freq node */ 
          temp -&gt; next = parent_node; /* parent node is temp next */
          ind = 1;
      }
      if (temp -&gt; next == NULL)
      {
          temp -&gt; next = parent_node; 
          ind = 1;          
      }
  }
  </code></pre>