If its a BST then the rightmost element will be the maximum followed by root
and left node
So we can use recursion

Working Code

struct node* findKthLargest(node* root, int& k)
{
  if(root==NULL){
     return NULL;
  }
  struct node* temp;
  temp=findKthLargest(root->right,k);
  k--;
  if(k==0)
     return root;
  if(k>0)
      temp=findKthLargest(root->left,k);
  return temp;
}

Regards

Ankur

---------- Forwarded message ----------
From: praveen raj <[email protected]>
Date: Fri, Sep 9, 2011 at 10:26 AM
Subject: Re: [algogeeks] Re: MICROSOFT
To: [email protected]


Through heapsort....

k times...
O(klogn)
.

With regards,

Praveen Raj
DCE-IT <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to