forked from MukulCode/CodingClubIndia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTLFunctions.cpp
More file actions
39 lines (28 loc) · 803 Bytes
/
STLFunctions.cpp
File metadata and controls
39 lines (28 loc) · 803 Bytes
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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//Set has two main properties- Unique, Sorted
void ExplainSet()
{
set<int> st;
st.insert(1);
st.emplace(2);
st.insert(2);
st.insert(4);
st.insert(3); //{1,2,3,4}
//{1,2,3,4,5}
auto it=st.find(3); //points at 3
//{1,2,3,4,5}
auto it=st.find(6); //points at st.end()
//{1,4,5}
st.erase(5); //erases 5, takes log time
int cnt =st.count(1);
auto it=st.find(3);
st.erase(it); //takes constant time
//{1,2,3,4,5}
auto it1=st.find(2);
auto it2=st.find(4);
st.erase(it1,it2); //after erasing->{1,4,5}
auto it=st.lower_bound(2);
auto it=st.upper_bound(3);
}