lower_bound()和upper_bound()如果搜下标到头返回啥

返回你要搜到的数组的下标的下一位

(区间是左闭右开的呀,返回那个开区间的坐标)

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
	int a[5]={1,2,3};
	int x=lower_bound(a,a+4,6)-a;
	printf("%d
",x);
	return 0;
}

返回值

4
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
	int a[5]={1,2,3};
	int x=upper_bound(a,a+4,6)-a;
	printf("%d
",x);
	return 0;
}

返回值

4
原文地址:https://www.cnblogs.com/Lour688/p/12774282.html