-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomStack
More file actions
45 lines (41 loc) · 890 Bytes
/
CustomStack
File metadata and controls
45 lines (41 loc) · 890 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
40
41
42
43
44
45
class CustomStack {
vector<int>obj;int size;
public:
CustomStack(int maxSize) {
size=maxSize;
}
void push(int x) {
if(obj.size()<size){
obj.push_back(x);
}
}
int pop() {
if(!obj.empty()){
int res=obj.back();
obj.pop_back();
return res;
}
return -1;
}
void increment(int k, int val) {
if(obj.size()<k){
for(int i=0;i<obj.size();i++){
obj[i]+=val;
}
}
else{
int i=0;
while(k>0){
obj[i++]+=val;
k--;
}
}
}
};
/**
* Your CustomStack object will be instantiated and called as such:
* CustomStack* obj = new CustomStack(maxSize);
* obj->push(x);
* int param_2 = obj->pop();
* obj->increment(k,val);
*/