双向排序(暂定)
作者:互联网
public static void sort(int arr[]) {
int start = 0;
int length = arr.length;
while (start < arr.length / 2) {
int min = arr[start], mini = start;
int max = arr[start], maxi = start;
for (int j = start; j < length; j++) {
if (min > arr[j]) {
min = arr[j];
mini = j;
}
if (max < arr[j]) {
max = arr[j];
maxi = j;
}
}
if (arr[start] != min) {
arr[mini] = arr[start];
arr[start] = min;
maxi++;
}
if (arr[length - 1] != max) {
arr[maxi] = arr[length - 1];
arr[length - 1] = max;
}
start++;
length--;
}
}
标签:arr,min,int,max,start,length,双向,排序,暂定 来源: https://www.cnblogs.com/gatico/p/12035024.html