Why don't I get expected bubbleSort with some inputs like 9 8 7 6? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why don't I get expected bubbleSort with some inputs like 9 8 7 6?

When the bubbleSort runs, sometimes no values get displayed. It seems this occurs when values are entered in decending order. https://code.sololearn.com/cyXN2S7817n0/?ref=app

21st Jun 2018, 6:59 AM
LottoMan
1 Answer
+ 1
You make an bad assumption: that "swapped" its false at last iteration thats not always true. Try to remove if statement if(swapped==false)
21st Jun 2018, 7:18 AM
KrOW
KrOW - avatar