#include<stdio.h>
#define N 30
char str[N]={NULL};
int st[N];
int t=0,k=0,a,t1=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;
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[i]=y;//存储单个字符
st[k]=i;//存储位置
if(y==' ');
if(y=='*'||y=='|')
{
//if(y=='*')
//str[i]=y;
if(str[0]!=NULL)//如果数组str非空,则输出
Print(0,str[0]);
t=0;
//continue;
}
/*if((y>='A'&&y<='Z')||(y>='a'&&y<='z'))//利用ASCII判断y是否是属于字母,并存储在数组str中
{
str[i]=y;
}*/
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!='
')//大神的方法,牛
p=InserQ(p,x);
q=p;
while(p.front!=p.rear)
p=DeleteQ(p);
printf("
该程序由渣渣,没有之一组的代表开发,感谢你使用我的程序!
");
}
void Print(int i,char y)//调用函数来判断并输出
{
a=st[i+1]+1;
if(y=='|'||y=='*')
{
k--;
return;
}
if(str[i]!='|')
a=t1++;
if(str[i+1]=='*')
{
printf("f(%d,%c)=%d
",i,'~',k);
printf("f(%d,%c)=%d
",k,y,k);
printf("f(%d,%c)=%d
",k,'~',a);
}
else
printf("f(%d,%c)=%d
",i,y,st[i+1]);
if(i<t)
Print(i+1,str[i+1]);
memset(str,0,N);//清空数组str里的所有元素
}