struct Treenode* itdeleteNode(struct Treenode* root, int v) { if (root == NULL) { return root; } struct Treenode* current = root; struct Treenode* parent = NULL; // Search for the node to delete while keeping track of its parent while (current != NULL && current->value != v) { parent = current; if (v < current->value) { current = current->left; } else { current = current->right; } } if (current == NULL) { // Node not found, return the original root return root; } if (current->left == NULL) { // Node with only a right child or no child struct Treenode* temp = current->right; free(current); if (parent == NULL) { return temp; // If the root itself is the node to be deleted } if (parent->left == current) { parent->left = temp; } else { parent->right = temp; } } else if (current->right == NULL) { // Node with only a left child struct Treenode* temp = current->left; free(current); if (parent == NULL) { return temp; // If the root itself is the node to be deleted } if (parent->left == current) { parent->left = temp; } else { parent->right = temp; } } else { // Node with two children struct Treenode* successorParent = current; struct Treenode* successor = current->right; while (successor->left != NULL) { successorParent = successor; successor = successor->left; } current->value = successor->value; if (successorParent->left == successor) { successorParent->left = successor->right; } else { successorParent->right = successor->right; } free(successor); } return root; }
Speed of presentation is excellent and explains with good examples.
Sir, your way of communication appreciable 🙏🇮🇳
I pay money for my university to teach me this yet i have to go onto youtube to learn. Thanks for this clear and concise playlist
Loving and swimming with the flow
I like this teacher. My type of teacher.
Thank you sir, the way you teach is awesome!
sir its very helpful
❤👌🙏🙏🙏
Thank you so much sir its very helpful
Problems with safe disposal of plastic
What about electrical materials
Sir imparntent section sir plis sir🙏
ty very much sir
"Is mugging up required?" - LOL..
Will depend on how best you get the basics and fundamentals into the listeners.
Hi , how can i take this course if I'm over says
can we get the texbook material
at 2:00
Im persuing material metelargy engineering is it safe
struct Treenode* itdeleteNode(struct Treenode* root, int v) {
if (root == NULL) {
return root;
}
struct Treenode* current = root;
struct Treenode* parent = NULL;
// Search for the node to delete while keeping track of its parent
while (current != NULL && current->value != v) {
parent = current;
if (v < current->value) {
current = current->left;
} else {
current = current->right;
}
}
if (current == NULL) {
// Node not found, return the original root
return root;
}
if (current->left == NULL) {
// Node with only a right child or no child
struct Treenode* temp = current->right;
free(current);
if (parent == NULL) {
return temp; // If the root itself is the node to be deleted
}
if (parent->left == current) {
parent->left = temp;
} else {
parent->right = temp;
}
} else if (current->right == NULL) {
// Node with only a left child
struct Treenode* temp = current->left;
free(current);
if (parent == NULL) {
return temp; // If the root itself is the node to be deleted
}
if (parent->left == current) {
parent->left = temp;
} else {
parent->right = temp;
}
} else {
// Node with two children
struct Treenode* successorParent = current;
struct Treenode* successor = current->right;
while (successor->left != NULL) {
successorParent = successor;
successor = successor->left;
}
current->value = successor->value;
if (successorParent->left == successor) {
successorParent->left = successor->right;
} else {
successorParent->right = successor->right;
}
free(successor);
}
return root;
}