0

I'm stuck on pset3. I'm trying to implement bubble sort but somehow its not sorting at all. Here's my program.Sort

And here's the output.enter image description here

Thanks.

1 Answer 1

0

In the for loop on line 45, you're iterating i - 1 times while you should iterate through the whole array comparing each adjacent pair of elements together and swapping them as necessary.

the pseudocode for bubble sort is

repeat n times
    for each element in the array (excluding the last element)
        if the current element is > the next element
            swap the current and next elements

see https://youtu.be/8Kp-8OGwphY!

1
  • Thanks a lot :) Commented Jun 29, 2015 at 17:20

You must log in to answer this question.

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