对一个给定的数组进行反转。
{23,14,88,5} ->
{5,88,14,23}
*/
public static void reverse(int[] arr)
{
for(int start=0,end=arr.length-1; start<end; start++,end--)
{
swap(arr,start,end);
}
}
public static void swap(int[] arr,int a,int b)
{
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
} |
|