这段程序怎么编??急~~~

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:48:56
编写依次输入A、B、C、D、E、F六个字符,利用一个栈和一个队列做缓冲,输出顺序为A、B、C、F、E、D的程序。谢谢!!!!!!
不好意思哦,用C语言编的~~

#include<stdio.h>
#include<stdlib.h>
#define elemtype int
#define MAXSIZE 100

typedef struct stack{
elemtype elem;
struct stack *next;
}STACK;
//链式存储的栈结构,及其相应算法

void InitStack(STACK *top)
{//初始化空栈
top->next=NULL;
}

void DestroyStack(STACK *top)
{//销毁栈,将栈所占内存空间释放
STACK *p;
p=top->next;
while(p!=NULL){
top->next=p->next;
free(p);
p=top->next;
}
}

int EmptyStack(STACK *top)
{//判断是否栈空,为空则返回1,否则返回0
if(top->next==NULL){
return 1;
}
else{
return 0;
}

}

int push(STACK *top, elemtype x)
{//元素x进栈操作,成功返回1,否则返回0
STACK *p;
p=(STACK *)malloc(sizeof(STACK));
p->elem=x;
p->next=top->next;
top->next=p;
return 1;
}

elemtype pop(STACK *top)
{//出栈操作,返回出栈元素
if(EmptyStack(top)){
printf("栈为空");