-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj10845.cpp
More file actions
89 lines (83 loc) · 1.65 KB
/
boj10845.cpp
File metadata and controls
89 lines (83 loc) · 1.65 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 큐 직접 구현
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
inline void Quick_IO(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
class queue{
private:
int* head;
int* tail;
int* arr;
public:
queue(int n){
arr = new int[n+1];
head = arr;
tail = arr;
}
int pop(){
return *(head++);
}
void push(int x){
*(tail++) = x;
}
bool empty(){
if(head==tail)
return true;
else return false;
}
int front(){
return *head;
}
int back(){
return *(tail-1);
}
int size(){
return tail - head;
}
};
int main(){
Quick_IO();
int N;
cin>>N;
queue stck(N);
while(N--){
string q;
cin>>q;
if(cin.peek()==' '){
int a;
cin>>a;
stck.push(a);
}else{
if(q=="pop"){
if(stck.empty()){
cout<<-1;
}else{
cout<<stck.pop();
}
}else if(q=="size"){
cout<<stck.size();
}else if(q=="empty"){
cout<<stck.empty();
}else if(q=="front"){
if(stck.empty()){
cout<<-1;
}else{
cout<< stck.front();
}
}else if(q=="back"){
if(stck.empty()){
cout<<-1;
}else{
cout<<stck.back();
}
}
cout<<"\n";
}
}
return 0;
}