- public class SelectSort {
-
- public static void main (String[] args) {
- int[] arr = {6,-1,99,25,8,0,3,-9};
- selectSort(arr,0,0);
- printArr(arr);
- }
-
-
- /*
- *利用递归进行选择排序
- */
- public static void selectSort(int[] arr, int start,int point) {
- int tmp;
- if (point < (arr.length-1)) {
- if(arr[start] > arr[point+1]) {
- tmp = arr[start];
- arr[start] = arr[point+1];
- arr[point+1] = tmp;
- }
- selectSort(arr,start,++point); // 进行内层递增
- }else {
- return;
- }
- point = start;
- selectSort(arr,++start,++point); //进行外层递增
- }
-
- public static void printArr (int[] arr) {
- for (int x = 0; x < arr.length; x++) {
- System.out.print(arr[x] + " ");
- }
- }
- }
复制代码
|