For an ordered symbol table st, the rank and select methods provide access through the position of the keys in the natural ordering.
int rank(Key k)
st.rank(k) should return the number of keys in st that are less than k.
If st.rank(k) returns 0, is the key k contained in st or not? What if st.rank(k) returns 1? What if st.rank(k) returns n where n = st.size()?
Key select(int i)
st.select(i) should return
- null if i < 0 or i >= st.size(), otherwise
- the key k in st such that there are i keys in st smaller than k; i.e., such that rank(k) is i
See code examples