title: Linked list recursive reverse
body: <p>I was looking at the code below from stanford library:</p>
  
  <pre><code>void recursiveReverse(struct node** head_ref)
  {
      struct node* first;
      struct node* rest;
  
      /* empty list */
      if (*head_ref == NULL)
         return;  
  
      /* suppose first = {1, 2, 3}, rest = {2, 3} */
      first = *head_ref;
      rest  = first-&gt;next;
  
      /* List has only one node */
      if (rest == NULL)
         return;  
  
      /* put the first element on the end of the list */
      recursiveReverse(&amp;rest);
      first-&gt;next-&gt;next  = first; 
  
      /* tricky step -- see the diagram */
      first-&gt;next  = NULL;         
  
      /* fix the head pointer */
      *head_ref = rest;
  }
  </code></pre>
  
  <p>What I don't understand is in the last recursive step for e.g if list is 1-2-3-4 Now for the last recursive step first will be 1 and rest will be 2. So if you set *head_ref = rest .. that makes the head of the list 2 ?? Can someone please explain how after reversing the head of the list becomes 4 ?? </p>