I think i figured out my bubble sort so far. However, if I try to test my implementation with ./find (I added a printf in helpers to get the sorted array) , the IDE doesn't allow me to input more than 3 numbers (those number are sorted but i wanted to try with more) and goes bust with a forth or more. Plus, I see my CPU usage going to 99%.

I'm posting my code in the first place to understand if it is correct (i hope it is)


this is what happens if i try to input a forth number



You're causing an infinite loop.

You're not doing correct bubble sort there.

Bubble sort requires two nested loops, not three.

If for example the inner loop used j as its counter, it would compare an element values[j] to the next element values[j+1]. Now you could try all kinds of optimizations on the range and direction of that inner loop (for example "shaker sort" is a bubble sort with alternating direction, or you could track the index of the last swap, or both), but it's always comparing two neighbouring elements.

  • HI Blauelf and thank you for pointing this out. Removing one for loop and adjusting the values in the square brackets did the trick. – Alessio Novi Apr 18 '17 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .