multiset c++
C++
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main()
{
// empty multiset container
multiset <int, greater <int> > gquiz1;
// insert elements in random order
gquiz1.insert(40);
gquiz1.insert(30);
gquiz1.insert(60);
gquiz1.insert(20);
gquiz1.insert(50);
gquiz1.insert(50); // 50 will be added again to the multiset unlike set
gquiz1.insert(10);
// printing multiset gquiz1
multiset <int, greater <int> > :: iterator itr;
cout << "\nThe multiset gquiz1 is : ";
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
// assigning the elements from gquiz1 to gquiz2
multiset <int> gquiz2(gquiz1.begin(), gquiz1.end());
// print all elements of the multiset gquiz2
cout << "\nThe multiset gquiz2 after assign from gquiz1 is : ";
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
// remove all elements up to element with value 30 in gquiz2
cout << "\ngquiz2 after removal of elements less than 30 : ";
gquiz2.erase(gquiz2.begin(), gquiz2.find(30));
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr)
{
cout << '\t' << *itr;
}
// remove all elements with value 50 in gquiz2
int num;
num = gquiz2.erase(50);
cout << "\ngquiz2.erase(50) : ";
cout << num << " removed \t" ;
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
//lower bound and upper bound for multiset gquiz1
cout << "gquiz1.lower_bound(40) : "
<< *gquiz1.lower_bound(40) << endl;
cout << "gquiz1.upper_bound(40) : "
<< *gquiz1.upper_bound(40) << endl;
//lower bound and upper bound for multiset gquiz2
cout << "gquiz2.lower_bound(40) : "
<< *gquiz2.lower_bound(40) << endl;
cout << "gquiz2.upper_bound(40) : "
<< *gquiz2.upper_bound(40) << endl;
return 0;
}
Also in C++:
- Title
- reference function in c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- rick astley - never gonna give you up
- Category
- C++
- Title
- How to check if a triangular cycle exists in a graph
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- mark occurances of elements in array cpp
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- substitution failure is not an error
- Category
- C++
- Title
- c++ program for addition of two numbers using functions
- Category
- C++
- Title
- create copy constructor c++
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- c++ vector
- Category
- C++
- Title
- what is atoi in strinf
- Category
- C++
- Title
- c++ iterate over vector
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- how to make a n*n 2d dynamic array in c++
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- linkedlist implementation in c++
- Category
- C++
- Title
- c++ for loop
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- initialize 3d vector c++
- Category
- C++
- Title
- how to avoid tle in c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- c++ calculator program using switch case
- Category
- C++
- Title
- __builtin_ctz
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- how to append one vector to another c++
- Category
- C++
- Title
- c++ char print fixed
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- c++ cout int
- Category
- C++
- Title
- subtracting two large numbers
- Category
- C++
- Title
- invalid types int int for array subscript c++
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- c++ multidimensional vector
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- tree traversal c++ in order
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- c++ set console title
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- how to convert n space separated integers in c++
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- cout does not name a type
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- multiple words C++ in same
- Category
- C++
- Title
- first prime numbers less than
- Category
- C++
- Title
- convert int to string c++
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- c++ class template
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- centos7 mlock2
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- equal elements in two arrays in c++
- Category
- C++
- Title
- c++ switch
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- c++ variable argument
- Category
- C++
- Title
- sorting of array in c++
- Category
- C++
- Title
- sleep system function linux c++
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- euler phi gfg
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- how to dynamically allocate an array c++
- Category
- C++
- Title
- c++ printf char as hex
- Category
- C++
- Title
- how to use wasd c++
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- check an stack is empty c++
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- how to find the size of a character array in c++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- calling a method on an object c++
- Category
- C++
- Title
- append string to another string c++
- Category
- C++
- Title
- ternary search c++
- Category
- C++
- Title
- iterate const vector
- Category
- C++