+ 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.

1 Answer

+ 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

Hot today

What is indentations... ?

6 Votes

int num = 2;
int x = 3;
if(num >= 2) {
if(x > 4) { num = 3; }
else { num = 4; }
}
else {x = 1; }

1 Votes

Need solution

0 Votes

About Java McQ

0 Votes

YouTube Link Finder

0 Votes

Need solution

0 Votes