-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset_stl.cpp
52 lines (43 loc) · 803 Bytes
/
set_stl.cpp
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
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
//set :- unique values
int main(){
set<int> st;
int n;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
st.insert(x); //log(container_size)
}
// you cant do this in set
// for(auto i:st){
// cout<<i<<" ";
// }
//you can only use iterators for the set in cpp
st.insert(0);
for(auto i=st.begin();i!=st.end();i++){
cout<< *i<<" ";
}
cout<<endl;
// erase set
//log n
// st.erase(st.begin());
auto itr = st.begin();
itr++;
st.erase(st.begin(),next(st.begin(),2));
for(auto i=st.begin();i!=st.end();i++){
cout<< *i<<" ";
}
// set find
cout<<"set1"<<endl;
set<int> st1;
st1.insert(2);
st1.insert(23);
st1.insert(1);
auto it0 = st1.find(1);
// auto it = st1.find(32);
cout<<distance(st1.begin(),it0);
}