title: Reverse of the linked list without changing the links of nodes
body: <p>I tried this code but I got a segmentation fault. How can I fix this error?</p>
  
  <pre><code>void rev()
  {
      struct node *p,*q;
      p=start;
      q=start;
  
      int count=0,temp,i,j;
  
      while(p!=0)
      {
          p=p-&gt;next;
          count++;
      }
      for(i=0; i&lt;(count/2); i++)
      {
          p=start;
          for(j=0; j&lt;(count-i); j++)
              p=p-&gt;next;
  
          temp=q-&gt;data;
          q-&gt;data=p-&gt;data;
          p-&gt;data=temp;
  
          q=q-&gt;next;
      }
   }
  </code></pre>
  
  <p>Here <code>p</code> and <code>q</code> are pointers. At first, both are pointing to start.
  Then, by using two loops, I swapped the values of first and last node, then second and second last and so on.</p>