Write BstQueries with your own BST whose nodes also store the size of their subtree. Read n and n distinct keys (inserted in that order), then query values x until the end of input. For each x print:
floor(x): the largest key ≤ x;ceiling(x): the smallest key ≥ x;rank(x): the number of keys smaller than x (use the subtree sizes — do not traverse the whole tree).
For the input
7
50 30 70 20 40 60 80
45 50 10 95 60
the program prints
Keys in the tree: 7
x = 45: floor 40, ceiling 50, rank 3
x = 50: floor 50, ceiling 50, rank 3
x = 10: floor none, ceiling 20, rank 0
x = 95: floor 80, ceiling none, rank 7
x = 60: floor 60, ceiling 60, rank 4