-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
153 lines (141 loc) · 2.83 KB
/
main.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
151
152
153
#include "RBtree.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void help() {
printf(
"\t-----<Menu>------\n"
"\tP - 좌석 확인하기\n"
"\tI - 삽입하기\n"
"\tD - 삭제하기\n"
"\tS - 좌석 예매하기\n"
"\tC - 예매 취소하기\n"
"\tH - 메뉴 확인\n"
"\tX - 종료하기\n"
);
}
/* Search 알고리즘 만들고, 예매기능 넣기.
트리 프린트할 때 어떤식으로 되는건지 확인하고, 노드 위치까지 프린트하기.
*/
int main() {
RBtree * tree = NULL;
int cmd = 0;
char num;
printf("프로그램 실행\n");
printf("1. 접속하기 2. 종료하기 \n");
scanf_s("%d", &cmd);
if (cmd == 2) {
printf("---종료합니다.---\n");
return 0;
}
help();
tree = RBcreate();
while (cmd != 2) {
int arg;
num = getchar();
switch (num) {
case 'F':
case 'f':
/* If we already had a tree, we need to free up
* the memory. */
if (tree != NULL) {
printf("Clear tree.\n");
RBfree(tree);
}
else {
printf("Tree is not exists.\n");
}
break;
case 'P':
case 'p':
if (tree == NULL) {
printf("Error: no tree loaded, cannot write.\n");
}
else {
RBprint(tree);
}
break;
case 'I':
case 'i':
printf("Key 입력: ");
if (tree == NULL) {
printf("No tree loaded - creating empty one.\n");
tree = RBcreate();
}
if (scanf_s("%d", &arg) != 1) {
printf("Error: must specify integer key to insert.\n");
}
else {
RBinsert(tree, arg);
}
break;
case 'D':
case 'd':
if (tree == NULL) {
printf("Error: no tree loaded, cannot delete.\n");
}
else {
if (scanf_s("%d", &arg) != 1) {
printf("Error: must specify integer key to delete.\n");
}
else {
RBdelete(tree, arg);
}
}
break;
case 'S':
case 's':
printf("예매 좌석: ");
if (tree == NULL) {
printf("Error: no tree loaded, cannot reserve.\n");
}
else {
if (scanf_s("%d", &arg) != 1) {
printf("Error: must specify integer key to reserve.\n");
}
else {
RBSearch(tree, arg);
}
}
break;
case 'C':
case 'c':
printf("좌석 입력: ");
if (tree == NULL) {
printf("Error: no tree loaded, cannot reserve.\n");
}
else {
if (scanf_s("%d", &arg) != 1) {
printf("Error: must specify integer key to reserve.\n");
}
else {
RBCancel(tree, arg);
}
}
break;
case 'H':
case 'h':
help();
break;
case 'X':
case 'x':
printf("-----종료합니다.-----\n");
cmd = 2;
break;
/* Corresponds to an empty command */
case '\n':
printf("Input: ");
break;
default:
printf("Error: unknown command `%c'.\n", num);
help();
break;
}
}
/* We need to free the tree. */
if (tree != NULL) {
RBfree(tree);
}
RBcleanup();
return 0;
}