TreeSet TreeMap

TreeSet:

(2)ceiling & floor

TreeSet的ceiling可以模拟upper_bound(获得更大范围里面最小的数),floor可以模拟 lower_bound(获得更小范围内最大的数)

16
15 treeset.ceiling(13) = 15 即 能上顶能封住13的数


12 treeset.floor(13) = 12 即 能下底能封住13的数
11

TreeMap:

(1) Define:

TreeMap map = new TreeMap<>();

(2) ceilingKey() & floorKey():

lowerKey(K key)
Returns the greatest key strictly less than the given key, or null if there is no such key.

floorKey(K key)
Returns the greatest key less than or equal to the given key, or null if there is no such key.

higherKey(K key)
Returns the least key strictly greater than the given key, or null if there is no such key.

ceilingKey(K key)
Returns the least key greater than or equal to the given key, or null if there is no such key.

你可能感兴趣的:(TreeSet TreeMap)