Associative Containers

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult. C.A.R. Hoare


Language C++ | Level Intermediate | Category Standard Template Library (STL) | 2015-11-17 04:25:33



Multiset is an ordered collection of items where the items may occur 0 or more times. The multiset elements are always sorted in ascending order.


Multiple keys with same values are allowed.
class template has a first template parameter specifying the type of objects to be stored in the set, and a second one specifying the type of a comparison function.
Ordered collection of items where the items may occur 0 or more times.

source Code

#include "stdafx.h"

#include < iostream >
#include < set >
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
	cout << "Create array and add to multiset" << endl;

	int myints[] = { 10, 20, 30, 20, 20 };
	multiset < int > mset(myints, myints + 5);      

	cout << "Display items from multiset:";
	for (multiset < int >::iterator it = mset.begin(); it != mset.end(); ++it)
		cout << ' ' << *it;
	cout << endl;
	return 0;



					Create array and add to multiset
					Display items from multiset: 10 20 20 20 30

When to use

Multiset implemented as binary search trees in most STL implementations. When you need binary search tree, you can use multiset.


Please login to add comments.