-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10845.cpp
More file actions
54 lines (47 loc) · 967 Bytes
/
Copy path10845.cpp
File metadata and controls
54 lines (47 loc) · 967 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
46
47
48
49
50
51
52
53
54
#include<iostream>
#include<string>
using namespace std;
int arr[10001];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testcase=0;
cin>>testcase;
string input;
int front=0,back=0;
for(int i=0;i<testcase;i++){
cin>>input;
int chk=0;
int pushnum=0;
if(input=="push"){
cin>>pushnum;
arr[back]=pushnum;
back++;
}
else if(input=="pop"){
if (front==back) cout<<"-1"<<'\n';
else{
cout<<arr[front]<<'\n';
arr[front]=0;
front++;
}
}
else if(input=="size"){
cout<<back-front<<'\n';
}
else if(input=="empty"){
if (front==back) cout<<"1"<<'\n';
else cout<<"0"<<'\n';
}
else if(input=="front"){
if (front==back) cout<<"-1"<<'\n';
else cout<<arr[front]<<'\n';
}
else if(input=="back"){
if (front==back) cout<<"-1"<<'\n';
else cout<<arr[back-1]<<'\n';
}
}
return 0;
}