list.cc
/* Reverse the list LIST in place, i.e., without modifying the links.  */
Reverse the list LIST in place, i.e., without modifying the links.
Reverse the list LIST in place i . e . without modifying the links .
static void
reverse_in_place (node *list)
{
  const int len = list_length (list);
  if (len < 2)
    return;
  int pos = len - 1;
  while (pos > 0)
    {
      node *n = list;
      for (size_t i = pos; i > 0; --i)
	n = n->next;
      std::swap (list->val, n->val);
      pos -= 2;
      list = list->next;
    }
}
static void reverse_in_place ( node * list ) { const int len = list_length ( list ) ; if ( len < 2 ) return ; int pos = len - 1 ; while ( pos > 0 ) { node * n = list ; for ( size_t i = pos ; i > 0 ; -- i ) n = n -> next ; std :: swap ( list -> val , n -> val ) ; pos -= 2 ; list = list -> next ; } }
Reverse the list LIST in place, i.e., without modifying the links.
Reverse the list LIST in place i . e . without modifying the links .
// Swap list[cur] and list[cur + pos] values. // Advance N by POS.