我想在给定元素的下限之前找到集合中不存在的元素,我想使用指针算术和 std::set::iterators 因为它们的行为像指针,这是我尝试的:
set<int>q;
set<int>::iterator curr;
set<int>::iterator strt;
l = num.size();
q.insert(num[l-1]);
strt = q.begin();
temp = 1;
int x;
for(int i=l-2;i>=0;i--)
{
curr = q.lower_bound(num[i]);
if(curr == q.end())
stats.push_back({temp,0});
else
{
x = curr-strt;//ERROR
stats.push_back({x,temp-x});
}
q.insert(num[i]);
temp++;
}
有没有办法在给定元素的下限之前找到集合中不存在的元素?