-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
63 lines (57 loc) · 1.44 KB
/
queue.c
File metadata and controls
63 lines (57 loc) · 1.44 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
#include<stdio.h>
int queue[5]; // 큐
void menuf(){
printf("\n1.큐에 삽입 2.큐에서 삭제");
printf("3.내용보기 4.종료");
}
void Enqueue(int* back, int item){
if(*back == 4){ // 큐가 배열이므로 0,1,2,3,4 4라면 가득찬 것
printf("큐가 가득참\n");
return;
}
queue[++ *back] = item; // 찬 공간 다음 공간에 삽입
}
int Dequeue(int* front, int back){
if(*front == back) { // front == back은 empty
return -1;
}
return queue[++ * front];
}
void Display(int front, int back){
if(front == back){
printf("큐가 비었음\n");
}
for(int i=front; i<back;){
printf("%4d", queue[++i]);
}
}
int main() {
int front = -1, back = -1;
int menu, item;
while(1) {
menuf();
scanf("%d", &menu);
switch(menu){
case 1:
scanf("%d", &item);
Enqueue(&back, item);
break;
case 2:
item = Dequeue(&front, back);
if(item == -1){
printf("큐가 비었음");
}else{
printf("%d가 삭제됨\n", item);
}
break;
case 3:
Display(front, back);
break;
case 4:
return 0;
default:
printf("다시 입력하세요");
}
}
return 0;
}