Create and return a new array that is a reversed copy of the array passed as a parameter.
The code I have is the following. I am stuck on the algorithm? This was an exam question but the exam is now over.
import java.util.*;
public class Q4_ArrayReverse
{
public static String[] reverse( String[] in )
{
String[] out = new String[ in.length ];
reverse( in, out, 0 );
return out;
}
///////////////////////////////////////////////////////////
//
// Given an input array, an output array and an index,
// copy the element at the index offset of the input array
// to the appropriate reversed position in the output array.
// i.e. in[ 0 ] -> out[ n - 1 ]
// in[ 1 ] => out[ n - 2 ]
// etc.
// After doing the copy for index, recurse for index + 1
// Be sure to quit when you get to the end of the array.
//
//////////////////////////////////////////////////////////
static void reverse( String[] in, String[] out, int index )
{
}
Q4_ArrayReverseis a hateful class name that doesn't match the Java naming convention.