STL Container7: muiltiset

来源:互联网 发布:相贯线切割机编程 编辑:程序博客网 时间:2024/06/07 00:11

// Multiset_Process.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

#include <iostream>

 

using std::cout;

using std::endl;

 

#include<set>

#include<iterator>

#include <algorithm>

 

typedef std::multiset< int, std::less< int > > ims;

 

 

int _tmain(int argc, _TCHAR* argv[])

{

    const int SIZE = 10;

    int a[SIZE] = { 7, 22, 9, 1, 18, 30, 100, 22, 85, 13 };

 

    ims intMultiset;

    std::ostream_iterator< int > outputIt( cout, " ");

 

    cout<<"There are currently "<< intMultiset.count( 15 )

        <<"values of 15 in the multiset/n";

 

    intMultiset.insert( 15 );

    intMultiset.insert( 15 );

 

    cout<<"After inserts, there are "

        << intMultiset.count( 15 )

        << " values of 15 in the multiset/n/n";

 

    ims::const_iterator result;

 

    result = intMultiset.find( 15 );

 

    if( result != intMultiset.end() )

        cout<<"Found value 15/n";

 

    result = intMultiset.find( 20 );

 

    if( result == intMultiset.end() )

        cout<<"Did not find value 20/n";

 

    intMultiset.insert( a, a+SIZE );

 

    cout<<"/nAfter insert, intMultiset contains:/n";

    std::copy( intMultiset.begin(), intMultiset.end(), outputIt );

 

    cout<<"/n/nLower bound of 22: "

        << *(intMultiset.lower_bound( 22 ) );

 

    cout<<"/nUpper bound of 22: "

        << *( intMultiset.upper_bound( 22 ) );

 

    std::pair< ims::const_iterator, ims::const_iterator > p;

 

    p= intMultiset.equal_range( 22 );

 

    cout<< "/n/nequal range of 22:"

        << "/n   Lower bound: " << *( p.first )

        << "/n   Upper bound: " << *( p.second );

 

    cout<<endl;

 

    return 0;

}

 

原创粉丝点击