Demonstration of Binary Search Tree
Demonstration of Binary Search Tree
int data;
TLNode left,right;
TLNode(int d)
{
data=d;
}
}
TLNode root;
else if(d<=root.data)
root.left=insert(d,root.left);
else
root.right=insert(d,root.right);
return root;
}
void inorder(TLNode r)
{
if(r==null)
return;
inorder(r.left);
System.out.println(r.data);
inorder(r.right);
}
else
{
if (root.left == null)
return root.right;
else if (root.right == null)
return root.left;
root.data = minValue(root.right);
root.right = delete(root.right, root.data);
}
return root;
}
int minValue(TLNode root)
{
int minv = root.data;
while (root.left != null)
{
minv = root.left.data;
root = root.left;
}
return minv;
}
TLNode find=ob.search(30,ob.root);
if(find==null)
System.out.println("not found");
else
System.out.println("found : "+find.data);
}
}
Output:
******60
20
20
30
60
70
80
found : 30