1 public static void sort(int arr[]) { 2 int start = 0; 3 int length = arr.length; 4 while (start < arr.length / 2) { 5 int min = arr[start], mini = start; 6 int max = arr[start], maxi = start; 7 for (int j = start; j < length; j++) { 8 if (min > arr[j]) { 9 min = arr[j]; 10 mini = j; 11 } 12 if (max < arr[j]) { 13 max = arr[j]; 14 maxi = j; 15 } 16 } 17 if (arr[start] != min) { 18 arr[mini] = arr[start]; 19 arr[start] = min; 20 maxi++; 21 } 22 if (arr[length - 1] != max) { 23 arr[maxi] = arr[length - 1]; 24 arr[length - 1] = max; 25 } 26 start++; 27 length--; 28 } 29 }