Skip to content

Commit eed7eb2

Browse files
authored
Create map_in_c++
1 parent 962c3b7 commit eed7eb2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

map_in_c++

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// main.cpp
3+
//
4+
// Created by Prince Kumar on 30/04/2020.
5+
// Copyright © 2020 Prince Kumar. All rights reserved.
6+
//
7+
// ---** MAP in C++ **---
8+
9+
#include <iostream>
10+
#include <map>
11+
using namespace std;
12+
int main(){
13+
// roll_num weight of student
14+
map < int , int > person;
15+
16+
// Insert the values in map
17+
person.insert(pair<int, int>(1,35));
18+
person.insert({2, 40});
19+
person.insert({3,50});
20+
person.insert({5, 10});
21+
22+
23+
// auto it = person.find(3);
24+
// person.erase(it);
25+
26+
//person.erase(5);
27+
28+
29+
// print
30+
for(auto itr = person.begin() ; itr!=person.end() ; ++itr){
31+
cout<<itr->first <<" " <<itr->second<<endl;
32+
}
33+
34+
// .begin() --> return iterator
35+
//auto var = person.begin();
36+
//cout<<"By var iterator " <<var->first <<" "<<var->second<<endl;
37+
38+
// .end() --> return iterator
39+
//auto var = person.end(); // Not actual map
40+
//cout<<"By var iterator " <<var->first <<" "<<var->second<<endl;
41+
42+
//cout<<person.size()<<endl;
43+
//cout<<person.max_size()<<endl;
44+
45+
// .erase()
46+
47+
// .empty() -->whether map is empty or not
48+
// 0 --> map is not empty
49+
// 1 --> map is empty
50+
51+
52+
person.clear(); // delete all the values in map
53+
cout<<"map is empty or not ? "<<person.empty()<<endl;
54+
55+
56+
57+
58+
}

0 commit comments

Comments
 (0)