-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.c
73 lines (72 loc) · 2.34 KB
/
test3.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
#include <stdio.h>
#include <stdlib.h>
#include "lab52.h" // 请不要删除本行头文件,否则检查不通过
int main(void) {
int input;
GoodsList *pList;
init_list(&pList);
save_to_file(pList);
exit(0);
while (1) {
puts("1.显示所有商品的信息\n"
"2.修改某个商品的信息\n"
"3.插入某个商品的信息\n"
"4.删除某个商品的信息\n"
"5.查找某个商品的信息\n"
"6.商品存盘并退出系统\n"
"7.对商品价格进行排序\n"
"8.(慎用)删除所有内容\n"
"其他.不存盘并退出系统");
printf("请输入数据:");
scanf(" %d", &input);
switch (input) {
case 1:
output_all_items(pList);
break;
case 2: {
GoodsInfo gf = read_goods_info();
char id[MAX_ID_LEN];
puts("请输入原商品id");
read_line(id, MAX_ID_LEN);
change_item(pList, id, gf);
break;
}
case 3: {
GoodsInfo gf = read_goods_info();
int i;
puts("请输入要插入的位置(0.将商品信息插入到链表尾部; 1.将商品信息插入到链表头部; i.将商品信息插入到链表中间第i号位置, 例如:输入3,应该在第二个节点后插入新节点)");
scanf("%d", &i);
insert_item(pList, gf, i);
break;
}
case 4: {
char id[MAX_ID_LEN];
puts("请输入商品id");
read_line(id, MAX_ID_LEN);
delete_item(pList, id);
break;
}
case 5: {
char id[MAX_ID_LEN];
puts("请输入商品id");
read_line(id, MAX_ID_LEN);
search_item(pList, id);
break;
}
case 6:
save_to_file(pList);
goto exit;
case 7:
bubble_sort(pList);
break;
case 8:
destory_list_and_file(&pList);
break;
default:
goto exit;
}
}
exit:
destory_list(&pList);
return 0;
}