[STL基础]set集合(二)

2014-11-24 08:28:37 · 作者: · 浏览: 1
pper_bound(42);
cout<<*itlows<<" "<<*itups<
std::pair::iterator,set::iterator> pa=myset.equal_range(42);
cout<<"the lower bound point to:"<<*pa.first<
cout<<"the upper bound point to:"<<*pa.second<
//equal_range():返回pair(iterator,iterator),pair中的第一个迭代器是lower_bound()返回的迭代器,pair中的第二个迭代器是upper_bound()返回的迭代器,如果两个迭代器相等,则说明map中不存在这个关键字
//lower_bound():返回是iterator,返回要查找关键字的下界(是一个迭代器)
//upper_bound():返回是iterator,返回要查找关键字的上界(是一个迭代器)
}
//遍历map中的数据
void test5()
{
//1.使用前向迭代器
//2.使用相反迭代器
int myint[]={75,23,65,42,13};
set myset(myint,myint+5);//初始化:[beg,end)
for (set::iterator it=myset.begin();it!=myset.end();it++)
{
cout<<*it<<" ";//13 23 42 65 75
}
cout<<"\nreverse myset:"<
for (set::reverse_iterator it=myset.rbegin();it!=myset.rend();it++)
{
cout<<*it<<" ";//75 65 42 23 13
}
cout<
}
void Test(char h)
{
cout<<"press key===="<
switch(h)
{
case '0': test0();break;
case '1': test1();break;
case '2': test2();break;
case '3': test3();break;
case '4': test4();break;
case '5': test5();break;
case 27: www.2cto.com
case 'q':exit(0);break;
default:cout<<"default "<
}
}
void main()
{
while(1)
{
Test(getch());
}
}