Delete Nodes Greater than K
Explanation:
check if root's data is greater than k then return its left node.
Code:
public Node deleteNode(Node root,int x)
{
if(root==null)
return null;
root.left=deleteNode(root.left,x);
root.right=deleteNode(root.right,x);
if(root.data>=x)
{
return root.left;
}
return root;
}
check if root's data is greater than k then return its left node.
Code:
public Node deleteNode(Node root,int x)
{
if(root==null)
return null;
root.left=deleteNode(root.left,x);
root.right=deleteNode(root.right,x);
if(root.data>=x)
{
return root.left;
}
return root;
}
0 Comments:
Post a Comment