Wednesday, September 11, 2013

Reverse a singly linked list


static void _inPlaceRev( Node *cursor, Node *prev) {
  if(!cursor) { 
    return;
  }
  _inPlaceRev(head, tail, cursor->next, cursor);
  cursor->next = prev;
}

static void inPlaceRev(LinkedList * _my) {
  _inPlaceRev(_my->head, NULL);
  //swap the head and tail
  _my->head ^= _my->tail;
  _my->tail ^= _my->head;
  _my->head ^= _my->tail;

}