-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabeleReservation System.c
150 lines (135 loc) · 3 KB
/
TabeleReservation System.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <stdio.h>
#include <stdlib.h>
#define MAX 20
int tableready = 0; //테이블 대기수
int select; //기능 선택
int people; //입력 인원수
int tablesize; //식탁 크기
int r_num = 9; //초기 대기번호
int n = 0;
int q = 0; //큐 인덱스
int result;//대기번호 반환
int result0; //인원수 반환
typedef struct element{
int key; //대기번호
int num; //인원수
}element;
element heap[20];
element queue[30];
void init(){ //큐 초기화
for(int i=0;i<30;i++){
queue[i].key = 0;
queue[i].num = 0;
}
}
void swap(int *a, int *b){
int tmp = *a;
*a = *b;
*b = tmp;
}
void push(element item){
if(n>MAX) return;
heap[++n] = item;
int child = n;
int parent = child/2;
while(child>1 && heap[parent].key<heap[child].key){
swap(&heap[parent].key, &heap[child].key);
swap(&heap[parent].num, &heap[child].num);
child = parent;
parent = child/2;
}
}
int pop(){
result = heap[1].key;
result0 = heap[1].num;
swap(&heap[1].key, &heap[n].key);
swap(&heap[1].num, &heap[n].num);
n--;
int parent = 1;
int child = 2;
if(child+1 <= n){
child = (heap[child].key > heap[child + 1].key) ? child : child + 1;
}
while(child <= n && heap[parent].key < heap[child].key){
swap(&heap[parent].key, &heap[child].key);
swap(&heap[parent].num, &heap[child].num);
parent = child;
child = child*2;
if(child + 1 <= n){
child = (heap[child].key > heap[child+1].key) ? child:child+1;
}
}
return result; //대기번호 반환
return result0; //인원수 반환
}
void s_print(){ //시작화면 출력
printf("Start of Program\n");
printf("기능\n");
printf("0.종료 1.대기접수 2.식탁배정\n");
printf("식탁 대기수: %d\n",tableready);
printf("-------------\n");
}
void sel_m(){ //기능선택 문구
printf("기능 선택?: ");
scanf("%d",&select);
}
void sel1(){
printf("대기번호 : %d\n",r_num);
printf("인원수?: ");
scanf("%d",&people);
printf("식탁 대기수 : %d\n",tableready);
printf("-------------\n");
}
void sel2(){
printf("식탁 크기?: ");
scanf("%d",&tablesize);
while(1){
pop();
if(result0<=tablesize){
printf("배정:: 대기번호: %d 인원수: %d\n",result,result0);
tableready = tableready - 1;
printf("식탁 대기수 : %d\n",tableready);
printf("-------------\n");
break;
}
else if(result0>tablesize){
queue[q].key = result;
queue[q].num = result0;
q = q+1;
if(n==0){
printf("배정불가::\n");
printf("식탁 대기수: %d\n",tableready);
printf("-------------\n");
break;
}
}
}
for(int i=0;i<=q;i++){
if(queue[i].key != 0 && queue[i].num != 0)
push(queue[i]);
}
init();
}
int main(void){
init();
element root;
s_print();
while(1){
sel_m();
if(select == 0){
printf("End of Program\n");
break;
}
else if(select == 1){
tableready = tableready + 1;
sel1();
root.key = r_num; //대기번호
root.num = people; //인원수
push(root);
r_num = r_num - 1;
}
else if(select == 2){
sel2();
}
}
}