lower_bound upper_bound

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main( )
{
    //lower_bound函数用法,这个函数用来返回要查找关键字的下界
    //upper_bound函数用法,这个函数用来返回要查找关键字的上界
    map<int,string>mp;
    mp[0]="abcdefg0";
    mp[1]="bcdefgh1";
    mp[2]="cdefgih2";
    mp[4]="defghts4";
    map<int,string>::iterator iter1,iter2;
    iter1 = mp.lower_bound(1);
    iter2 = mp.upper_bound(2);
    cout<<iter1->second<<endl;// bcdefgh1
    cout<<iter2->second<<endl;//defghts4
    pair<map<int,string>::iterator,map<int,string>::iterator>mappair;
    mappair = mp.equal_range(7);
    if(mappair.first == mappair.second)
        cout<<"NOT FOUNDING"<<endl;
    else
        cout<<"FIND"<<endl;
    return 0;
}

posted on 2011-07-28 22:14  more think, more gains  阅读(200)  评论(0)    收藏  举报

导航