set容器的查找

set容器的查找


#include 
using namespace std;
#include 
int main()
{
	setset1;
	for(int i=0;i<10;i++)
	{
		set1.insert(i+1);
	}
	for(set::iterator it=set1.begin();it!=set1.end();it++)
	{
		cout<<*it<<" ";
	}
	cout<	set::iterator it0=set1.find(5);
	cout<<"it0:"<<*it0<
	int num1=set1.count(5);
	cout<<"num1:"<

	set::iterator it1=set1.lower_bound(5);//大于等于5的元素的迭代器的位置
	cout<<"it1:"<<*it1<	set::iterator it2=set1.upper_bound(5);//大于5的元素的迭代器的位置
	cout<<"it2:"<<*it2<

	//typedef pair _Pairib;
	//typedef pair _Pairii;
	//typedef pair _Paircc;

	pair::iterator, set::iterator> mypair=set1.equal_range(5);
	set::iterator it3=mypair.first;
	cout<<"it3:"<<*it3<//5 
	set::iterator it4=mypair.second;
	cout<<"it4:"<<*it4<//6 
	//把元素5删除掉
	set1.erase(5);
	pair::iterator, set::iterator> mypair2=set1.equal_range(5);
	set::iterator it5=mypair2.first;
	cout<<"it5:"<<*it5<//5删除后 6
	set::iterator it6=mypair2.second;
	cout<<"it6:"<<*it6<//5删除后 6
	system("pause");
	return 0;
}


set容器的查找_第1张图片

你可能感兴趣的:(C/C++编程)