-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_Lab09_3.c
76 lines (71 loc) · 1.08 KB
/
2_Lab09_3.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
//10845
#include <stdio.h>
#include <string.h>
int que[10000];
int que_size=0;
void push(int data){
que[que_size++]=data;
}
void pop(){
int i;
if(que_size>0){
printf("%d\n",que[0]);
for(i=0;i<que_size-1;i++){
que[i]=que[i+1];
}
que_size--;
}
else
printf("%d\n",-1);
}
void size(){
printf("%d\n",que_size);
}
void empty(){
if(que_size>0)
printf("%d\n",0);
else
printf("%d\n",1);
}
void front(){
if(que_size>0)
printf("%d\n",que[0]);
else
printf("%d\n",-1);
}
void back(){
if(que_size>0)
printf("%d\n",que[que_size-1]);
else
printf("%d\n",-1);
}
int main(void) {
int N, i;
scanf("%d",&N);
int que[N];
char command[6];
for(i=0;i<N;i++){
scanf("%s",command);
if(command[3]=='h'){
int data;
scanf("%d",&data);
push(data);
}
else if(command[1]=='o'){
pop();
}
else if(command[0]=='s'){
size();
}
else if(command[0]=='e'){
empty();
}
else if(command[0]=='f'){
front();
}
else if(command[0]=='b'){
back();
}
}
return 0;
}