-
Notifications
You must be signed in to change notification settings - Fork 0
/
8주차_과제1(10845).c
85 lines (74 loc) · 1.4 KB
/
8주차_과제1(10845).c
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
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int Queue[10000] = { 0 };
int Front = 0;
int Rear = 0;
void push(int num)
{
Queue[Front++] = num;
}
int pop()
{
if (Rear == Front)
return -1;
int tmp = Queue[Rear];
Queue[Rear++] = 0;
return tmp;
}
int size()
{
return Front - Rear;
}
int empty()
{
if (Front == Rear)
return 1;
else
return 0;
}
int front()
{
if (Front == Rear)
return -1;
else
return Queue[Rear];
}
int back()
{
if (Front == Rear)
return -1;
else
return Queue[Front - 1];
}
int main()
{
int num;
vector<int> ans;
char cmd[8] = { 0 };
scanf("%d", &num);
for (int i = 0; i < num; i++)
{
scanf("%s", cmd);
if (strcmp(cmd, "push") == 0)
{
int integer;
scanf("%d", &integer);
push(integer);
}
if (strcmp(cmd, "pop") == 0)
ans.push_back(pop());
if (strcmp(cmd, "size") == 0)
ans.push_back(size());
if (strcmp(cmd, "empty") == 0)
ans.push_back(empty());
if (strcmp(cmd, "front") == 0)
ans.push_back(front());
if (strcmp(cmd, "back") == 0)
ans.push_back(back());
}
vector<int>::iterator iter;
for (iter = ans.begin(); iter != ans.end(); iter++)
printf("%d\n", *iter);
}