title: Reverse a linked list after a given value, without creating new nodes
body: <p>I'm really stuck with that exercise. I can reverse a linked list with no problem, but I don't know how to do it without creating new nodes.</p>
  
  <p>Implement a function reverse() to reverse the elements in a linked list
  from the first occurrence of a given value. 
  e.g. given the input A B C D E F and the value D return the list A B C F E D</p>
  
  <p>You should do this inplace without creating new nodes. </p>
  
  <pre><code>struct Node
  {
      struct Node* next;
      int val;
  };
  
  void reverse( struct Node* head, int val);
  </code></pre>
  
  <p>Could you give me some tips?</p>
  
  <p>This is what I have right now :</p>
  
  <pre><code>struct Node
  {
      struct Node* next;
      int val;
  };
  
  void reverse(struct Node* head)
  {
     struct Node *p = head,
                  *q = NULL,
                  *r;
      while (p != NULL)
      {
          r = q;
          q = p;
          p = p-&gt;next;
          q-&gt;next = r;
      }
      q = head;
  }
  
  void reverseAfter( struct Node* head, int val )
  {
      while(head)
      {
          if(head-&gt;val == val)
              reverse(head);
          else
              head = head-&gt;next;  
      }
  }
  </code></pre>