[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Bubble sort (double direction)


sort( r, lo, up ) ArrayToSort r; int lo, up; {int i, j; while (up>lo) { j = lo; for ( i=lo; i<up; 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 source (411b.sort.c)



© Addison-Wesley Publishing Co. Inc.