Sì... me ne sono accorto dopo. L'errore stà nel fatto che non hai usato bene le parentesi graffe e quindi scambi valori degli indici, che poi sconfinano..
Questa è la versione riveduta e corretta:
codice:
class Ordina2 {
public static void main(String[] args) {
int array[] = {10,6,4,2,40,20,40,5,6};
selectionSort(array);
for(int i=0;i<array.length;i++)
System.out.println(array[i]);
}
public static void selectionSort(int number[]){
int startIndex, minIndex, length, temp, min;
length = number.length;
for(startIndex=0;startIndex<length-1;startIndex++) {
for(minIndex=startIndex+1; minIndex<length; minIndex++) {
if(number[minIndex]<number[startIndex]) {
temp = number[startIndex];
number[startIndex] = number[minIndex];
number[minIndex] = temp;
}
}
}
}
}
Ciao.