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

kth largest Value in BST


Code:

 int c=0;
    public void show(Node root,int k)
    {
        if(root==null || c>=k)
        return;
        if(root.right!=null)
        show(root.right,k);
        if(++c==k)
        {System.out.println(root.data);
        return;}
        if(root.left!=null)
        show(root.left,k);
    }
    public void kthLargest(Node root,int k)
    {
        show(root,k);
        
    }

0 Comments:

Post a Comment

Stats