Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node* suprima(Node* node, int key)
- {
- // base case
- if (!node)
- return node;
- if (key < node->key)
- return suprima(node->left, key);
- else if (key > node->key)
- return suprima(node->right, key);
- else { // key == node->key
- // 1 fiu sau 0 fii
- if (!node->left) {
- Node* aux = node->right;
- free(node);
- return aux;
- }
- else if (!node->right) {
- Node* aux = node->left;
- free(node);
- return aux;
- }
- // 2 fii
- // succesor
- Node* succ = succesor(node);
- // copie key succesor -> node
- node->key = succ->key;
- // sterge succesor
- node->right = suprima(node->right, succ->key);
- }
- return node;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement