#include"head.h"
int main() {
int choice;
char ch, * chptr;
sep_stack* sep_s=(sep_stack*)malloc(sizeof(sep_stack));
link_stack link_s=(link_stack_node*)malloc(sizeof(link_stack_node));
sep_queue* sep_q=(sep_queue*)malloc(sizeof(sep_queue));
link_queue* link_q = (link_queue*)malloc(sizeof(link_queue));
sepstack_init(sep_s);
linkstack_init(link_s);
sepqueue_init(sep_q);
if (!linkqueue_init(link_q)) {
return;
}
while (1) {
puts("-----------栈与队列实现-----------");
puts("---顺序栈:-----------------------");
puts("---------1.入栈-------------------");
puts("---------2.出栈(全部)-------------");
puts("---链栈:-------------------------");
puts("---------3.入栈-------------------");
puts("---------4.出栈(全部)-------------");
puts("---循环队列:----------------------");
puts("---------5.入队-------------------");
puts("---------6.出队(全部)-------------");
puts("---链队列:----------------------");
puts("---------7.入队-------------------");
puts("---------8.出队(全部)-------------");
puts("---------9.退出-------------------");
scanf("%d", &choice);
getchar();
switch (choice) {
case(1): {
while (1 == scanf("%c", &ch)) {
if ('\n' == ch) {
break;
}
sepstack_push(sep_s, ch);
}
break;
}
case(2): {
chptr = &ch;
while (sepstack_pop(sep_s, chptr)) {
printf("%c", *chptr);
}
printf("\n");
break;
}
case(3): {while (1 == scanf("%c", &ch)) {
if ('\n' == ch) {
break;
}
linkstack_push(link_s, ch);
}
break;
}
case(4): {
chptr = &ch;
while (linkstack_pop(link_s, chptr)) {
printf("%c", *chptr);
}
printf("\n");
break;
}
case(5): {
while (1 == scanf("%c", &ch)) {
if ('\n' == ch) {
break;
}
sepqueue_enter(sep_q, ch);
}
break;
}
case(6): {
chptr = &ch;
while (sepqueue_delet(sep_q, chptr)) {
printf("%c", *chptr);
}
printf("\n");
break;
}
case(7): {
while (1 == scanf("%c", &ch)) {
if ('\n' == ch) {
break;
}
linkqueue_enter(link_q, ch);
}
break;
}
case(8): {
chptr = &ch;
while (linkqueue_delet(link_q, chptr)) {
printf("%c", *chptr);
}
printf("\n");
break;
}
case(9): {
goto label;
}
default: {
printf("输入错误");
}
}
}
label:return 0;
}
评论0