-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
174 lines (150 loc) · 3.59 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#define USE_TEST_DATA
#include "Compatibility.h"
#include "GLOBAL.h"
#include "LinkedList.h"
static void add_test_data(struct LinkedList* list)
{
struct NodeData node_list[] =
{
{"zhangsan", "1", "1", "none"},
{"lisi", "3", "3", "none"},
{"wangwu", "2", "2", "none"},
{"zhaoliu", "9", "9", "none"},
{"xiaoming", "7", "7", "none"},
{"laowang", "0", "0", "none"},
};
for (size_t i = 0; i < 6; i++)
{
struct NodeData* node_data = CreateNodeData(node_list[i].name, node_list[i].phone, node_list[i].role, node_list[i].institute);
list->PushBackNode(list, CreateNode(node_data, NULL, NULL));
}
}
static void Add(struct LinkedList* list)
{
printf("========== 添加数据 ==========\n");
struct NodeData* node_data = CreateNodeDataFromConsoleInput();
if (node_data == NULL)
{
printf("添加失败\n");
return;
}
struct Node* node = CreateNode(node_data, NULL, NULL);
list->PushBackNode(list, node);
}
static void Remove(struct LinkedList* list)
{
struct Node* result_list[FILTER_RESULT_SIZE] = { NULL };
FullFilter(list, result_list);
while (1)
{
ClearConsole();
PrintFilteredResultsInConsole("筛选结果:\n", result_list);
if (!CmdConfirm("是否继续筛选?"))
break;
IncrementalFilter(result_list);
}
ClearConsole();
PrintFilteredResultsInConsole("筛选结果:\n", result_list);
if (!CmdConfirm("删除以上数据?"))
return;
struct Node* node = NULL;
struct Node* dead_node = NULL;
for (size_t i = 0; i < FILTER_RESULT_SIZE; ++i)
{
if (result_list[i] == NULL)
continue;
list->RemoveNode(list, result_list[i]);
}
printf("删除完成\n");
PauseConsole();
ClearConsole();
}
static void Update(struct LinkedList* list)
{
struct Node* result_list[FILTER_RESULT_SIZE] = { NULL };
FullFilter(list, result_list);
while (1)
{
ClearConsole();
PrintFilteredResultsInConsole("筛选结果:\n", result_list);
if (!CmdConfirm("是否继续筛选?"))
break;
IncrementalFilter(result_list);
}
ClearConsole();
PrintFilteredResultsInConsole("筛选结果:\n", result_list);
if (!CmdConfirm("更新以上数据?"))
return;
for (size_t i = 0; i < FILTER_RESULT_SIZE; ++i)
{
if (result_list[i] == NULL)
continue;
UpdateNodeDataFromConsoleInput(result_list[i]->data);
}
ClearConsole();
}
static void Query(struct LinkedList* list)
{
struct Node* result_list[FILTER_RESULT_SIZE] = { NULL };
FullFilter(list, result_list);
ClearConsole();
PrintFilteredResultsInConsole("查询结果:\n", result_list);
while (CmdConfirm("针对以上数据进行筛选?"))
{
IncrementalFilter(result_list);
ClearConsole();
PrintFilteredResultsInConsole("筛选结果:\n", result_list);
}
while (CmdConfirm("对以上数据进行排序?"))
{
Sorter(result_list);
ClearConsole();
PrintFilteredResultsInConsole("排序结果:\n", result_list);
}
}
int main(void)
{
struct LinkedList* list = LinkedListConstructor();
if (list == NULL)
return -1;
#ifdef USE_TEST_DATA
add_test_data(list);
#endif
int run = 1;
while (run)
{
printf("\n========== 教师管理系统 ==========\n");
printf("1.添加数据\n");
printf("2.删除数据\n");
printf("3.修改数据\n");
printf("4.查询数据\n");
printf("0.退出程序\n");
printf("请输入你的选择: ");
switch (CmdGetInt())
{
case 1:
ClearConsole();
Add(list);
break;
case 2:
ClearConsole();
Remove(list);
break;
case 3:
ClearConsole();
Update(list);
break;
case 4:
ClearConsole();
Query(list);
break;
case 0:
run = 0;
break;
default:
printf("错误的输入\n");
}
}
LinkedListDestructor(list);
return 0;
}