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