Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C program - modify bubble sort - need someone to check my code

raeikoraeiko Member Posts: 17
Hello,

i need to sort out this problem:

"The bubble sort represented in fig 6.15 of your text book is inefficient for large arrays. Make the following simple modifications to improve the performance of the bubble sort.
After the first pass, the largest number is guaranteed to be in the highest-numbered element of the array; after the second pass, the two highest numbers are

Comments

  • Malcolm_McLeanMalcolm_McLean Member Posts: 254 ✭✭
    Post error.

    Your first pass is labelled "pass 1", which means that the inner loop only counts up to 9 -1 = 8 on the first pass.

    The best way to change it is to count from 0 to i < 9, which is the C way of doing things, because array indices start with 0.

Sign In or Register to comment.