.
.
# include
# include
# include
#include conio.h
/*定义全局变量*/
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define NULL 0
#define OVERFLOW -2
#define MAXSIZE 100
#define stack_init_size 100
#define stackincrement 10
Typedef char selemType
Typedef char qelemType
Typedef char elemType
Typedef int status
CHAR E;
char demon[MAXSIZE];
/*类型和基本任务*/
Typedef struct
{
SelemType * base
SelemType * top
Int stacksize
} sqstack
Status initstack (sqstack *s)
{
s-base=(selem type *)malloc(stack _ init _ size * size of(selem type));
If(!S-base)结束(概述);
s-top=s-base;
s-stacksize=stack _ init _ size;
Return OK
}/*创建堆栈*/
Status push (sqstack * s、s elemtype e)
{
If(s-top-s-base=s-stacksize)
{
s-base=(elem type *)realloc(s-base,(s-stack size stack increment)* size of(elem type))
If(!S-base)结束(概述);
s-top=s-base s-stacksize;
s-stacksize=stack increment;
}
*(s-top)=e;
Return OK
}/*堆栈*/
Status pop (sqstack * s、s elemtype * e)
{
if(s-top==s-base)return ERROR;
* e=*(-(s-top));
Return OK
}/*堆栈*/
/*队列类型和基本任务*/
Typedef struct qnode
{
QelemType数据;
Struct qnode * next
}qnode、* queueptr
Typedef struct
{
Queueptr front
Queueptr rear
} linkqueue
Status initqueue(linkqueue *q)
{
q-front=q-rear=(queueptr)malloc(size of(qnode));
If(!Q-front)结束(概述);
q-front-next=NULL;
Return OK
}/*创建队列*/
Status enqueue (link queue * q,qelemtype e)
{
queueptr p;
p=(queueptr)malloc(size of(qnode));
>if(!p) exit(OVERFLOW);p->data=e;
p->next=NULL;
q->rear->next=p;
q->rear=p;
return OK;
}/*入队*/
status dequeue(linkqueue *q,qelemType *e)
{
queueptr p;
if(q->front==q->rear) return ERROR;
p=q->front->next;
*e=p->data;
q->front->next=p->next;
if(q->rear==p)
{
q->rear=q->front;
}
free(p);
return OK;
}/*出队*/
/*括号内元素入栈处理函数*/
void tempstack(sqstack *temps)
{
int i=0;
char t;
char c;
c=demon[i];
for(i=0;c!='#';i++)/*遍历数组*/
{
c=demon[i];
if(c=='(')/*遇到开括号*/
{
t=demon[i+1];/*取括号中的首字母*/
push(temps,t);/*入栈*/
i++;/*指向首字母*/
do
{
i++;
c=demon[i];
push(temps,c)/*第一次循环将次字母入栈*/;
push(temps,t);/*再将首字母进栈*/
}while(c!=')');/*直到括号中元素全部进栈*/
pop(temps,&t);/*将多余进栈的首字母t出栈*/
pop(temps,&t); /*将多余进栈的')'出栈*/
}
}
}/*临时栈*/
/*特殊入队函数*/
void spenqueue(linkqueue *q,char key)
{
int j=0;
char a[5];
switch(key) /*判断大写字母对应的字符串*/
{
case'A':strcpy(a,"ase");break;
case'B':strcpy(a,"tAdA");break;
case'C':strcpy(a,"abc");break;
case'D':strcpy(a,"def");break;
case'E':strcpy(a,"ghi");break;
case'F':strcpy(a,"klm");break;
case'H':strcpy(a,"mop");break;
default:strcpy(a,"???"); /*不能翻译的魔王语言以"???"输出*/
}
while(a[j]!='