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


Leftist trees deletion (Pascal version available)


tree merge( a, b ) tree a, b; { if ( a == NULL ) return( b ); else if ( b == NULL ) return( a ); else if ( a->k > b->k ) { a->right = merge( a->right, b ); fixdist( a ); return( a ); } else { b->right = merge( a, b->right ); fixdist( b ); return( b ); } }; tree delete( pq ) tree pq; { if ( pq == NULL ) Error /*** delete on an empty queue ***/; else return( merge( pq->left, pq->right ) ); };

C source (516.del.c) Pascal source (516.del.p)



© Addison-Wesley Publishing Co. Inc.