Multiset in C++ Standard Template Library [STL]
Multisets are a type of associative containers similar to the set, with the exception that multiple elements can have the same values. Some Basic Functions associated with multiset:
- begin[] Returns an iterator to the first element in the multiset.
- end[] Returns an iterator to the theoretical element that follows the last element in the multiset.
- size[] Returns the number of elements in the multiset.
- max_size[] Returns the maximum number of elements that the multiset can hold.
- empty[] Returns whether the multiset is empty
Implementation:
CPP
// CPP Program to demonstrate the // implementation of multiset #include #include #include using namespace std; int main[] { // empty multiset container multiset gquiz1; // insert elements in random order gquiz1.insert[40]; gquiz1.insert[30]; gquiz1.insert[60]; gquiz1.insert[20]; gquiz1.insert[50]; // 50 will be added again to // the multiset unlike set gquiz1.insert[50]; gquiz1.insert[10]; // printing multiset gquiz1 multiset::iterator itr; cout Chủ Đề |