tree insert( new, pq )
tree new, pq;
{
tree p;
if ( pq == NULL ) return( new );
else if ( pq->k >= new->k ) {
/*** Insert above subtree ***/
new->left = pq;
return( new );
}
else {
p = pq;
while ( p->left != NULL )
if ( p->left->k >= new->k ) {
/*** Insert in right subtree ***/
p->right = insert( new, p->right );
return( pq );
}
else p = p->left;
/*** Insert at bottom left ***/
p->left = new;
};
return( pq );
};
|