Bubble sort (double direction) - C
 


sort( r, lo, up )
ArrayToSort r;
int lo, up;

{int i, j;
while (up>lo) {
j = lo;
for ( i=lo; i if ( r[i].k > r[i+1].k ) {
exchange( r, i, i+1 );
j = i;}
up = j;
for ( i=up; i>lo; i-- )
if ( r[i].k < r[i-1].k ) {
exchange( r, i, i-1 );
j = i;}
lo = j;
}
}

(c) Shilpa Sayura Foundation 2006-2017