
So I have this in a class file. It is supposed to be an insertion sorter:
int min, index=0, temp;
for(int i=0;i<sorted.length;i++){
min=sorted[i];
for(int j=i+1;j<sorted.length;j++){
if(sorted[j]<min){
index=j;
min=sorted[j];
}
}
temp=sorted[index];
sorted[index]=sorted[i];
sorted[i]=temp;
}
and from all I can see everything should be good. Except, it gives the following output:
-100, -8, 1, 6, 11, 17, 23, 24, 33, 35, 42, 43, 76, 79, 84, 88, 99, 124, 240, 242, 268, 357, 9000, 424, 2424
I don't understand why it won't order the last 3. Help anyone?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.