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 <praveen0...@gmail.com> Date: Fri, Sep 9, 2011 at 10:26 AM Subject: Re: [algogeeks] Re: MICROSOFT To: algogeeks@googlegroups.com Through heapsort.... k times... O(klogn) . With regards, Praveen Raj DCE-IT <praveen0...@gmail.com> -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.