File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include<iostream>
2+
#include<iterator>
3+
#include<map>
4+
using namespace std;
5+
int main ()
6+
{
7+
map<int, int> gquiz1;
8+
gquiz1.insert(pair<int, int>(1, 40));
9+
gquiz1.insert(pair<int, int>(2, 30));
10+
gquiz1.insert(pair<int, int>(3, 60));
11+
gquiz1.insert(pair<int, int>(4, 20));
12+
gquiz1.insert(pair<int, int>(5, 50));
13+
gquiz1.insert(pair<int, int>(6, 50));
14+
gquiz1.insert(pair<int, int>(7, 10));
15+
16+
map<int, int>::iterator itr;
17+
cout << "\nThe map gquiz1 is : \n";
18+
cout << "\tKEY\tELEMENT\n";
19+
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {
20+
cout << '\t' << itr->first
21+
<< '\t' << itr->second << '\n';
22+
}
23+
cout << endl;
24+
// assigning the elements from gquiz1 to gquiz2
25+
map<int, int> gquiz2(gquiz1.begin(), gquiz1.end());
26+
27+
// print all elements of the map gquiz2
28+
cout << "\nThe map gquiz2 after"
29+
<< " assign from gquiz1 is : \n";
30+
cout << "\tKEY\tELEMENT\n";
31+
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
32+
cout << '\t' << itr->first
33+
<< '\t' << itr->second << '\n';
34+
}
35+
cout << endl;
36+
37+
cout << "\ngquiz2 after removal of"
38+
" elements less than key=3 : \n";
39+
cout << "\tKEY\tELEMENT\n";
40+
gquiz2.erase(gquiz2.begin(), gquiz2.find(3));
41+
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
42+
cout << '\t' << itr->first
43+
<< '\t' << itr->second << '\n';
44+
}
45+
int num;
46+
num = gquiz2.erase(4);
47+
cout << "\ngquiz2.erase(4) : ";
48+
cout << num << " removed \n";
49+
cout << "\tKEY\tELEMENT\n";
50+
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
51+
cout << '\t' << itr->first
52+
<< '\t' << itr->second << '\n';
53+
}
54+
55+
cout << endl;
56+
57+
cout << "gquiz1.lower_bound(5) : "
58+
<< "\tKEY = ";
59+
cout << gquiz1.lower_bound(5)->first << '\t';
60+
cout << "\tELEMENT = "
61+
<< gquiz1.lower_bound(5)->second << endl;
62+
cout << "gquiz1.upper_bound(5) : "
63+
<< "\tKEY = ";
64+
cout << gquiz1.upper_bound(5)->first << '\t';
65+
cout << "\tELEMENT = "
66+
<< gquiz1.upper_bound(5)->second << endl;
67+
68+
69+
return 0;
70+
}
71+

0 commit comments

Comments
 (0)