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


Replacement selection distribution


distribute( ) {int i, hbot, s; typekey lastout; for (i=0; i<m; i++) { buff[i]=ReadFile( 1 ); if ( eof(1) ) break; } i--; while (i>=0) { for (hbot=0; hbot<i; ) insert( ++hbot, buff ); /*** start a new sequence ***/ s=nextfile(); while (hbot>= 0) { lastout = Buff[0].k; WriteFile( s, Buff[0] ); Buff[0] = Buff[hbot]; siftup( Buff, 0, hbot-1 ); if ( !Eof(1) ) Buff[hbot] = ReadFile(1); if ( Eof(1) ) Buff[hbot--] = Buff[i--]; else if ( Buff[hbot].k <lastout ) hbot--; else insert( hbot, buff ); } } };

C source (4411.distr.c)



© Addison-Wesley Publishing Co. Inc.