Skip to content

Commit

Permalink
Create 10845_큐.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
witheunjin committed Mar 3, 2020
1 parent c0a1627 commit c0794da
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions BaekJoon/10845_큐.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <queue>
using namespace std;

queue<int> q;
void match(string para) {
if (para == "push") {
int x;
cin >> x;
q.push(x);
}
else if (para == "pop") {
if (q.empty()) cout << -1 << endl;
else { cout << q.front() << endl; q.pop(); }
}
else if (para == "size") {
cout << q.size() << endl;
}
else if (para == "empty") {
if (q.empty()) cout << 1 << endl;
else cout << 0 << endl;
}
else if (para == "front") {
if (q.empty()) cout << -1 << endl;
else cout << q.front() << endl;
}
else if (para == "back") {
if (q.empty()) cout << -1 << endl;
else cout << q.back() << endl;
}
}
int main() {
int N;
cin >> N;
string command;
for (int i = 0; i < N; ++i) {
cin >> command;
match(command);
}
return 0;
}

0 comments on commit c0794da

Please sign in to comment.