I am learning about recursion and wanted to convert my loops into a recursive function ? What should be the correct answer for this code be (Suppose that I already wrote the flip method to reverse elements in an array) ? Thanks,
/**
* Sorts an array of integers by repeatedly reversing
* subranges within the array. Prints the flip sequence.
*/
public static void sort( int[] array)
{
int size = array.length;
if (!Ordered(array, size)){
for(int i = size-1; i > 0; i--)
{
int j = findMax(array, 0, i );
int flipPosition;
if( j != i )
{
if( j != 0 ) {
flip( array, 0, j );
flipPosition = size-j;
System.out.print( flipPosition + " " );
}
flip( array, 0, i );
flipPosition = size-i;
System.out.print( flipPosition + " " );
}
}
}
System.out.println( 0 );
}