Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Wednesday, August 9, 2017

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;
             }

0 Comments:

Post a Comment

Stats