Skip to content

Commit dcb27a0

Browse files
committed
stl added
1 parent 1b1b656 commit dcb27a0

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

map.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
// key = value pair
7+
// map store unique keys , in sorted order
8+
map<int, int> mpp;
9+
10+
// everything is sorted
11+
// multimap is key sorted but not unique
12+
// TC - O(1)
13+
// unordered_map is key unique but not sorted
14+
15+
for (const auto &pair : mpp)
16+
{
17+
cout << "Key: " << pair.first << ", Value: " << pair.second << endl;
18+
}
19+
20+
return 0;
21+
}

set.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
// everything is sorted and unique
7+
set<int> s1;
8+
9+
s1.insert(1);
10+
s1.insert(10);
11+
s1.insert(10); // <-- will not add
12+
s1.insert(5);
13+
14+
// everything is sorted
15+
// multiset is sorted but not unique
16+
// TC - O(1)
17+
// unordered_set is unique but not sorted
18+
19+
cout << s1.size();
20+
21+
return 0;
22+
}

0 commit comments

Comments
 (0)