BST - 2
BST - 2
h>
#include<malloc.h>
struct node{
int data;
};
if(root!=NULL){
preOrder(root->left);
preOrder(root->right);
if(root!=NULL){
postOrder(root->left);
postOrder(root->right);
}
}
if(root!=NULL){
inOrder(root->left);
inOrder(root->right);
if(root!=NULL){
if(!isBST(root->left)){
return 0;
return 0;
prev = root;
return isBST(root->right);
else{
return 1;
while(root!=NULL){
if(key == root->data){
return root;
}
else if(key<root->data){
root = root->left;
else{
root = root->right;
return NULL;
while(root!=NULL){
prev = root;
if(key==root->data){
return;
else if(key<root->data){
root = root->left;
else{
root = root->right;
if(key<prev->data){
prev->left = new;
else{
prev->right = new;
}
}
root = root->left;
while (root->right!=NULL)
root = root->right;
return root;
if (root == NULL){
return NULL;
if (root->left==NULL&&root->right==NULL){
free(root);
return NULL;
else{
iPre = inOrderPredecessor(root);
root->data = iPre->data;
return root;
int main(){
// 5
// /\
// 3 6
// / \
// 1 4
p->left = p1;
p->right = p2;
p1->left = p3;
p1->right = p4;
inOrder(p);
printf("\n");
deleteNode(p, 3);
inOrder(p);
return 0;