Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void del(node *peak)
- {
- if (peak->l == NULL && peak->r == NULL)
- {
- if (peak->prev != NULL && peak->prev->key > peak->key)
- {
- peak->prev->l = NULL;
- } else if (peak->prev != NULL && peak->prev->key < peak->key)
- {
- peak->prev->r = NULL;
- }
- free(peak);
- peak = NULL;
- return;
- }
- if (peak->r == NULL)
- {
- if (peak->prev != NULL && peak->prev->key > peak->key)
- {
- peak->prev->l = peak->l;
- } else if (peak->prev != NULL && peak->prev->key < peak->key)
- {
- peak->prev->r = peak->l;
- }
- free(peak);
- return;
- }
- node *cur = peak->r;
- while (cur->l != NULL)
- {
- cur = cur->l;
- }
- peak->key = cur->key;
- del(cur);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement