#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Queue
{
private:
int* queue;
int first = 0, end = 0;
int index = 0;
int output = 0;
public:
Queue(int num)
{
queue = new int[num];
}
~Queue()
{
delete[] queue;
}
public:
void Push(int num)
{
queue[index] = num;
index++;
}
int Pop()
{
if (first == index)
{
return -1;
}
else
{
output = queue[first];
first++;
return output;
}
}
int Size()
{
if ((index - first) <= 0)
{
return 0;
}
return (index - first);
}
bool empty()
{
if (Size() == 0)
{
return true;
}
else
{
return false;
}
}
int front()
{
if (Size() == 0)
{
return -1;
}
return queue[first];
}
int back()
{
if (Size() == 0)
{
return -1;
}
return queue[index-1];
}
};
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int input = 0;
cin >> input;
Queue q(input);
for (int i = 0; i < input; ++i)
{
string order;
cin >> order;
if (order == "push")
{
int num = 0;
cin >> num;
q.Push(num);
}
else if (order == "pop")
{
cout << q.Pop() << "\n";
}
else if (order == "size")
{
cout << q.Size() << "\n";
}
else if (order == "empty")
{
cout << q.empty() << "\n";
}
else if (order == "front")
{
cout << q.front() << "\n";
}
else if (order == "back")
{
cout << q.back() << "\n";
}
}
return 0;
}
코딩 테스트