C++STLトレーナー(multisetの使用)

1654 ワード

  • vectorの使用
  • listの使用
  • dequeの使用
  • setの使用
  • mapの使用
  • multisetの使用
  • multimapの使用
  • #include   
    #include   
    using namespace std;  
      
    int main()  
    {  
        ///1.      
        multiset num;  
        multiset::iterator iter,beg,end;  
        cout << num.max_size() << endl;///multiset      
        cout << endl;  
      
        ///2.       
        for (int i = 0; i < 10; i++)  
            num.insert(i);  
        cout << num.size() << endl;  
        cout << endl;  
      
        ///3.     
        for (iter = num.begin(); iter != num.end(); iter++)  
            cout << *iter << " " ;  
        cout << endl;  
        cout << endl;  
      
        ///4.     
      
        iter = num.find(1);  
        if (iter != num.end())  
            cout << *iter << endl;  
        else  
            cout << -1 << endl;  
      
        iter = num.find(99);  
        if (iter != num.end())  
            cout << *iter << endl;  
        else  
            cout << -1 << endl;  
        cout << endl;  
      
        beg=num.lower_bound(2);  
        end=num.upper_bound(7);  
        for (; beg != end; beg++)  
            cout << *beg << " " ;  
        cout << endl;  
      
        ///5.     
        iter = num.find(1);  
        num.erase(iter);  
        cout << num.size() << endl;  
        for (iter = num.begin(); iter != num.end(); iter++)  
            cout << *iter << " " ;  
        cout << endl;  
        cout << endl;  
      
        ///6.        
        if (!num.empty())  
            num.clear();  
    }