Advertisement
Jathin

Untitled

Aug 13th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // Author : jb
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. class node
  5. {
  6. int val;
  7. node* left;
  8. node* right;
  9. }
  10. void inorder(node* root, int k)
  11. {
  12. if(root->left == NULL && root->right == NULL)
  13. {
  14. return;
  15. }
  16. if(root->right != NULL)
  17. inorder(root->right,k);
  18. k--;
  19. if(k == 1) // ?? k = 0 OR 1
  20. {
  21. return root->val;
  22. }
  23. if(root->left != NULL)
  24. inorder(root->left,--k);
  25. }
  26. int find_kth_largest(node* root, int k)
  27. {
  28. return (inorder(root,k));
  29. }
  30.  
  31. int32_t main()
  32. {
  33. node* root = new node()
  34.  
  35.  
  36.  
  37. }
  38.  
  39.  
  40. // 7 k = 2
  41. // / \
  42. // 5 9
  43. // / \ / \ // 0 1 2 3 4 5 6 n = 7
  44. // 3 6 8 10 // 3 5 6 7 8 9 10 arr[n - k]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement