-
递归式:
public class SwpChange {
public static void main(String[] args) {
int[] arr = { 1, 2, 3, 4 };
fullSort(arr, 0, arr.length - 1);
}
public static void fullSort(int[] arr,int start,int end) {
if(start == end) {
for(int i:arr) {
System.out.print(i+" ");
}
System.out.println();
return ;
}
//交换
for(int i=start;i<=end;i++) {
swap(arr,i, start);
fullSort(arr, start+1, end);
swap(arr,i, start);
}
}
public static void swap(int[] arr,int x,int y) {
int t = arr[x];
arr[x] = arr[y];
arr[y] = t;
}
}