First of all don't mince about using an array name and a size - if you have to do it recursively use a couple of pointers to the first and last characters to be swapped. Something like:
void reverse_range( int *first_to_swap, int *last_to_swap )
{
if( first_to_swap < last_to_swap )
{
*first_to_swap ^= *last_to_swap ^= *first_to_swap ^= *last_to_swap;
reverse_range( first_to_swap++, last_to_swap-- );
}
}
(This is untested BTW, so don't be surprised if it's buggy. Likewise if you have to only have one parameter or some other balls ache of an artificial restriction then you converting the code is easy enough - it's just work.)
This is instructive 'cause If you compare this to the iterative version...
void reverse_range( int *first_to_swap, int *last_to_swap )
{
while( first_to_swap < last_to_swap )
{
*first_to_swap ^= *last_to_swap ^= *first_to_swap ^= *last_to_swap;
first_to_swap++, last_to_swap--;
}
}
you'll get a general pattern as to how to make a recursive version out of an iterative implementation. Replace the while with a conditional and instead of updating the iteration state call the function again with what would be the updated variables.
More importantly you get the
opposite - how to convert from a recursive implementation to an iterative one which is often more important. Loads of problems can be expressed easier as a recursive solution but
usually an iterative solution is faster. Having the mental tools to switch between the two is a big help.