-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdequebasic.cpp
More file actions
56 lines (52 loc) · 1.08 KB
/
Copy pathdequebasic.cpp
File metadata and controls
56 lines (52 loc) · 1.08 KB
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
#include <iostream>
#include <deque>
using namespace std;
//Data structure with min/max operations in O(1) time
struct MyDS{
deque<int>dq;
void insertMin(int x){
dq.push_front(x);
}
void insertMax(int x){
dq.push_back(x);
}
int getMin(){
return dq.front();
}
int getMax(){
return dq.back();
}
void extractMin(){
dq.pop_front();
}
void extractMax(){
dq.pop_back();
}
};
//Sliding Window Maximum
void PrintMaxk(int arr[], int n, int k){
deque<int> dq;
}
int main(){
// deque<int> dq;
// dq.push_front(5);
// dq.push_back(50);
// // for(auto x : dq){ //Traversing dq
// // cout << x << " ";
// // }
// // cout << dq.front() << " " << dq.back() << " " << dq.size();
// auto it = dq.begin();
// it++;
// dq.insert(it, 20);
// dq.pop_front();
// for(auto x : dq){
// cout << x << " ";
// }
MyDS ds;
ds.insertMin(15);
ds.insertMax(20);
cout << ds.getMax();
ds.extractMax();
cout << ds.getMin();
return 0;
}