+ 1
Hello guys,can someone help me fix this in my bubble sort algorithm?
I have bubble sort algorithm but the largest number in the array does not show after it has been sorted, everything works fine except for that missing number. https://code.sololearn.com/cF3IrKxghXf1/?ref=app
3 Respostas
+ 4
Hi,
see attached code
https://code.sololearn.com/c0oyIgAywCQ1/#java
+ 6
for(int j=0; j<listSize-1; j++){
System.out.print(list[j]+" ");
}
The last value j takes is (listSize-2), the last element in your array is at the position (listSize-1).
By the way, after each pass, you can decrease the limit of j by 1 instead of using a fixed (listSize-1), since the last elements are garanteed to be at the right place.