0

here i have two bubble sort versions.

void bsort()
{
        int i,j,jc=0,ic=0,temp,swap=1;

       //for(i=0;i<NOE & swap;i++){ this one or
        for(i=0;i<NOE-1 & swap;i++){ \\ this 
        swap=0,ic++;
         for(j=0;j<NOE-1-i;j++){
                jc++;
                if(a[j]>a[j+1]){
                        temp = a[j];
                        a[j] = a[j+1];
                        a[j+1] = temp;
                        swap = 1;
                        }
                }
        }
printf("jc=%d ic=%d\n",jc,ic);
}

i checked it .

in first case it only repeats one extra time which is not nedded .
other than that is there any situation where we get different results with different stataments.
Thanks,

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by hiraksarkardg
0

here i have two bubble sort versions.

//for(i=0;i<NOE & swap;i++){ this one or

I think there will be one more "&" in line no. 6. But it won't help improving the performance though.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.