-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
133 lines (109 loc) · 2.05 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
/**********************
**主函数, 测试
***********************/
#include "Main_First.h"
#include "Data.h"
#include "Data_Base.h"
#include "Test.h"
#include <time.h> /*随机数*/
int main(void)
{
int select; /*保存选择变量*/
size_t pos; /*位序*/
Elem e; /*保存从函数返回的结点的值*/
Elem v; /*保存传递给函数的结点的值*/
size_t i= 0;
LINKQUEUE Q;
InitQueue(&Q);
srand((int)time(NULL));
while (i < 10)
{
InsertQueue(&Q, rand()%20);
++i;
}
while (1) /*while_@1*/
{
if (!Q.front)
{
printf("队列不存在!\n");
break;
}
system("cls");
Menu();
printf("请输入您的选择(1~10):");
scanf("%d", &select);
getchar();
switch (select) /*switch_@1*/
{
case 1: /*入队*/
v = InputValue("入队元素为:");
if (FAILE == InsertQueue(&Q, v))
{
printf("入队失败!\n");
}
else
{
printf("入队成功!\n");
}
getchar();
break;
case 2: /*输出队列*/
printf("队列为:");
TraveQueue(&Q);
getchar();
break;
case 3: /*出队*/
if (OK == DeleteQueue(&Q, &e))
{
printf("出队成功,删除的元素是%d!\n", e);
}
else
{
printf("删除失败!\n");
}
getchar();
break;
case 4: /*输出队列的长度*/
printf("表长为: %d \n", QueueLength(&Q));
getchar();
break;
case 5: /*清空队列*/
ClearQueue(&Q);
printf("该表已经清空!\n");
getchar();
break;
case 6: /*返回队头元素*/
if (OK == GetHead(&Q, &e))
{
printf("该结点为:%d\n", e);
}
else
{
printf("不存在!\n");
}
getchar();
break;
case 7: /*判断队列是否为空*/
if (QueueEmpty(&Q) == TRUE)
{
printf("队列为空!\n");
}
else
{
printf("队列非空!\n");
}
getchar();
break;
case 8: /*销毁队列*/
DestroyQueue(&Q);
printf("队列已删除!\n");
getchar();
break;
default:
printf("请重新选择!\n");
getchar();
break;
}/*switch_@1*/
} /*while_@1*/
return EXIT_SUCCESS;
}