When passing an array in the selection function, I'm getting the required sorted array only for positive real numbers but for the negative numbers it is failing to do the same.
static void selection(int[] array) {
for (int i = 0; i < array.length; i++) {
int last = array.length - i - 1;
int max= getMaxIndex(array, 0, last);
swap(array, max, last);
}
}
static void swap(int[] arr, int first, int second) {
int temp = arr[first];
arr[first] = arr[second];
arr[second] = temp;
}
static int getMaxIndex(int[] arr, int start, int last) {
int max = start;
for (int i = 0; i < last; i++) {
if (arr[max] < arr[i]) {
max = i;
}
}
return max;
}