Question: Implement the member function int rank(T & val, TNode node), which returns the number of values in the tree that are less than val. Examples.

 Implement the member function int rank(T & val, TNode node), whichreturns the number of values in the tree that are less than

Implement the member function int rank(T & val, TNode node), which returns the number of values in the tree that are less than val. Examples. In the illustration above: rank(10, root) should return 6. rank(9, root) should return 5. rank(20, root) should return 8. N. rank(4, root) should return 2. rank(2, root) should return 0. Complete the following code to perform this task: (assume that the BST has no duplicates and that val is not necessarily in the tree) 1 template 2 int BST:: rank(T& val, TNode * node) { 3 if (node == nullptr) 4 return B 5 6 if (val == node->val) 7 return 8 else if (val val) 9 return D 10 else if (val > node->val) 11 return E 13 ) Hint: Remember that each node stores the size of the subtree rooted at that node. 1 https://elearning.psut.edu.jo/mod/quiz/attempt.php?attempt=163144&cmid=64544&page=1 PSUT E-LEARNING The host has opened Breakout Rooms. Please wat to be assigned Question 3 Implement the member function int rank(T & val, TNode node), which returns the number of values in the tree that are less than val. Examples. In the illustration above: Not yet answered rank(10, root) should return 6. Marked out of 3.00 rank(9, root) should return 5. Flag question ^ rank(20, root) should return 8. rank(4, root) should return 2. rank(2, root) should return O. Complete the following code to perform this task: (assume that the BST has no duplicates and that val is not necessarily in the tree) 1 template 2 int BST:: rank (T& val, TNode * node) { 3 if (node == nullptr) 4 return B 5 6 if (val == node->val) return 8. else if (val val) 9 return D 10 else if (val > node->val) 11 return 13 ) Hint: Remember that each node stores the size of the sub rooted hat node

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!