#include<stdio.h>
#define N 30
char str[N]={NULL};
void Print(int i,char y);
int st[N];
int t=0,k=0;
struct node//定义一个队列
{
char data;
struct node * next;
};
typedef struct node QueueNode;
struct node2//定义一个链队列
{
QueueNode *front;
QueueNode *rear;
};
typedef struct node2 Queue;
Queue InitQueue()//初始化队列
{
Queue Q;
Q.front=(QueueNode *)malloc(sizeof(QueueNode));
Q.front->next=NULL;
Q.rear=Q.front;
return(Q);
}
Queue InserQ(Queue Q,char x)//x进队列
{
QueueNode *p;
p=(QueueNode *)malloc(sizeof(QueueNode));
p->data=x;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
return(Q);
}
Queue DeleteQ(Queue Q)//出队列
{
int i=t++,j;
QueueNode *p;
char y=NULL;
if(Q.front==Q.rear)
{
printf("队列为,无法出队列!");//判断队列是否为空
return(Q);
}
p=Q.front->next;
y=Q.front->next->data;//将队列中的元素赋值给y
Q.front->next=p->next;
if(p==Q.rear)
Q.rear=Q.front;
str[t]=y;
st[k]=t;
if(y!='|')
{
if(p->next->data=='*'&&p->next!=NULL)
{
str[t]='~';
Print(0,'~');
str[t+1]=y;
Print(t,y);
str[t+2]='~';
k--;
Print(t,'~');
free(p->next);
}
else
Print(i,y);
}
if(y=='|')
{
k--;
t--;
}
k++;
free(p);
return Q;
}
void Print(int i,char y);//调用函数来判断并输出
main()
{
char x,y;
Queue p,q;
p=InitQueue();
printf("请输入正规式:");
while(scanf("%c",&x)==1&&x!='\n')//大神的方法,牛
p=InserQ(p,x);
q=p;
while(p.front!=p.rear)
p=DeleteQ(p);
}
void Print(int i,char y)//调用函数来判断并输出
{
printf("f(%d,%c)=%d\n",i,y,st[k]);
memset(str,0,N);//清空数组str里的所有元素
}