+ 2

Duplicates from multiset

Hi Please refer code below: https://code.sololearn.com/c0a21a0a15A1 it works for vector. In case of multiset, we can easily find count of some number using count method. Can we not use lower_bound and upper_bound for same in case of multiset? Just change vector to multiset in above function and observe that it throws compile time error.

5th May 2021, 6:54 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Odpowiedź
+ 1
Both upper_bound() and lower_bound() works with std::multiset also. If you look at the error message generated by compiler, you can see that it is complaining about now knowing how to subtract 2 iterators of a multiset, which is totally valid as unlike vector, is typically implemented as a binary search tree and subtracting 2 iterators pointing to different nodes doesn't make sense. You can see(in the following program) that lower_bound and upper_bound are doing their job as intended. 👇 https://code.sololearn.com/cp1EYpUN1obd/?ref=app
5th May 2021, 9:58 AM
Arsenic
Arsenic - avatar