-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
281 lines (276 loc) · 6.33 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#include<stdio.h>
#include<stdlib.h>
#include"queue.h"
int main()
{
AQueue Q;
LQueue q;
int data, l;
void* k; k = &l;
char option='\0',choice='\0', selection='\0', c_data;
float f_data;
InitAQueue(&Q);
InitLQueue(&q);
printf("\t选择循环队列还是链式队列\n");
printf("\t1.循环队列\n");
printf("\t2.链式队列\n");
do {
option = getchar();
if (option == '1')
{
for (int flag = 1; flag != 0;)
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
system("cls");
printf("****************菜单****************\n");
printf("\t1.初始化队列\n");
printf("\t2.销毁队列\n");
printf("\t3.检查队列是否已满\n");
printf("\t4.检查队列是否为空\n");
printf("\t5.查看队头元素\n");
printf("\t6.确定队列长度\n");
printf("\t7.入队操作\n");
printf("\t8.出队操作\n");
printf("\t9.清空队列\n");
printf("\tt.遍历函数操作\n");
printf("\t0:退出\n");
printf("************************************\n");
choice = getchar();
system("cls");
switch (choice)
{
case '1':
{
InitAQueue(&Q);
printf("初始化成功\n");
system("pause"); break;
}
case '2':
{
DestoryAQueue(&Q);
printf("销毁成功\n");
system("pause"); break;
}
case '3':
{
if (IsFullAQueue(&Q) == TRUE)
printf("队列满\n");
else
printf("队列未满\n");
system("pause"); break;
}
case '4':
{
if (IsEmptyAQueue(&Q) == TRUE)
printf("队列空\n");
else
printf("队列未空\n");
system("pause"); break;
}
case '5':
{
if (GetHeadAQueue(&Q,&k) == TRUE)
APrint(&k);
else
printf("获取失败\n");
system("pause"); break;
}
case '6':
{
printf("队列长度为:%d\n", LengthAQueue(&Q));
system("pause"); break;
}
case '7':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);//清空键盘缓存
printf("输入要入列的数据的类型\n1.整形\n2.字符\n3.浮点型\n");
selection = getchar();
printf("输入要入列的数据:\n");
switch (selection)
{
case '1':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%d", &data);
if (EnAQueue(&Q, &data) == TRUE)
printf("入队成功\n");
else
printf("入队失败\n");
system("pause"); break;
}
case '2':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%c", &c_data);
if (EnAQueue(&Q, &c_data) == TRUE)
printf("入队成功\n");
else
printf("入队失败\n");
system("pause"); break;
}
case '3':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%f", &f_data);
if (EnAQueue(&Q, &f_data) == TRUE)
printf("入队成功\n");
else
printf("入队失败\n");
system("pause"); break;
}
default:break;
}
break;
}
case '8':
{
if (DeAQueue(&Q) == TRUE)
printf("出队成功\n");
else
printf("出队失败\n");
system("pause"); break;
}
case '9':
{
ClearAQueue(&Q); printf("成功");
system("pause");
break;
}
case 't':
{
if (TraverseAQueue(&Q, APrint) == TRUE)
printf("遍历成功\n");
else
printf("遍历失败\n");
system("pause");
break;
}
case '0':flag = 0; system("pause"); break;
default:printf("错误,请重输\n");
}
}
}
else if (option == '2')
for (int flag = 1; flag != 0;)
{
system("cls");
printf("****************MENU****************\n");
printf("\t1.初始化队列\n");
printf("\t2.销毁队列\n");
printf("\t3.检查队列是否为空\n");
printf("\t4.查看队头元素\n");
printf("\t5.确定队列长度\n");
printf("\t6.入队操作\n");
printf("\t7.出队操作\n");
printf("\t8.清空队列\n");
printf("\t9.遍历函数操作\n");
printf("************************************\n");
printf("请输入你的选择\n");
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%c", &choice);
system("cls");
switch (choice)
{
case '1':
{
InitLQueue(&q);
printf("初始化成功\n");
break;
}
case '2':
{
DestoryLQueue(&q);
printf("销毁成功\n");
break;
}
case '3':
{
if (IsEmptyLQueue(&q) == TRUE)
printf("队列空\n");
else
printf("队列未空\n");
break;
}
case '4':
{
if (GetHeadLQueue(&q, &k) == TRUE)
APrint(&k);
else
printf("获取失败\n");
break;
}
case '5':
{
printf("队列长度为:%d\n", LengthLQueue(&q));
break;
}
case '6':
{
printf("输入要输入的数据的类型\n1.整形\t2.字符\t3.浮点型\n");
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%c", &selection);
printf("输入要输入的数据:\n");
switch (selection)
{
case '1':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%d", &data);
if (EnLQueue(&q, &data) == TRUE)
printf("入队成功\n");
else
printf("入队失败\n");
break;
}
case '2':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%c", &c_data);
if (EnLQueue(&q, &c_data) == TRUE)
printf("入队成功\n");
else
printf("入队失败\n");
break;
}
case '3':
{
char ch; while ((ch = getchar()) != '\n' && ch != EOF);
scanf_s("%f", &f_data);
if (EnLQueue(&q, &f_data) == TRUE)
printf("入队成功\n");
else
printf("入队失败\n");
break;
}
}
break;
}
case '7':
{
if (DeLQueue(&q) == TRUE)
printf("出队成功\n");
else
printf("出队失败\n");
break;
}
case '8':
{
ClearLQueue(&q); printf("成功");
break;
}
case '9':
{
if (TraverseLQueue(&q, APrint) == TRUE)
printf("遍历成功\n");
else
printf("遍历失败\n");
break;
}
default:printf("错误,请重输\n");
}
}
if (option != '1' && option != '2')
printf("错误,请重输\n");
} while (option != '1' &&option != '2');
return 0;
}