int funkth(node *root,int k) { queue<node *> q; q.insert(root); node *temp; while(!q.empty()) { temp=q.top(); q.pop(); if(temp->l) q.insert(temp->l); if(temp->r) q.insert(temp->r); makeheapk(temp->value); //make minheap of size k } return topheap(); //return top element of heap }
any corrections please? On Sun, Sep 4, 2011 at 10:20 AM, sukran dhawan <sukrandha...@gmail.com>wrote: > for bst > step 1 :count the number of nodes in a tree > step2: traverse in inorder.after each node visit decrement n. if n == k > then the result > > On Sun, Sep 4, 2011 at 12:33 AM, teja bala <pawanjalsa.t...@gmail.com>wrote: > >> //Asked in MS please help me with the coding or Give an algorithm >> >> >> Write code to return the kth largest element in a tree ...>>> function >> prototype is int fucnkth(node *root,int k) >> >> -- >> 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. > -- ........................ *MOHIT VERMA* -- 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.