title: Change the order of nodes in a single-linked list
body: <p>Say we have a list 1-2-3-4-5 (values of list can be without order, for example 2-4-5-3-1);<br/>
  The task is to reorder nodes of list (not values) in the way like this:
  1-5-2-4-3.<br/>
  I wrote the function that uses 2 temporary variables and 1 pointer. But the problem is I don't know how to set the "next" pointer in penultimate node to "NULL" without defining the second temporary pointer in function.
  Is there a more efficient way to do this?</p>
  
  <pre><code>void Swap(Node* begin)
  {
      if (begin-&gt;next != NULL || begin-&gt;next-&gt;next != NULL)
      {
          Node temp1 = *begin; //this variable is used for iteration
          Node* temp2 = begin; //pointer to the target node
          Node prev; //get the adress of last node
          while (temp1.next != NULL)
          {
              prev = temp1;
              temp1 = *temp1.next;
          }
          prev.next-&gt;next = temp2-&gt;next;
          temp2-&gt;next = prev.next;
          Swap(prev.next-&gt;next);
      }
  
  }
  </code></pre>