+ 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

17th Jan 2019, 3:41 PM
Ben Acq
Ben Acq - avatar
3 Answers
17th Jan 2019, 3:58 PM
notqueued
notqueued - avatar
+ 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.
17th Jan 2019, 3:55 PM
Zen
Zen - avatar
+ 2
Thanks guys Zen and notqueued
17th Jan 2019, 4:06 PM
Ben Acq
Ben Acq - avatar