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 ) );
};
|