#include <stdio.h>#defineN 30Charstr[n]={NULL};intSt[n];intt=0, k=0, a,t1=0;structNode//Define a queue{ Chardata; structNode *next;}; typedefstructnode Queuenode;structNode2//define a chain queue{Queuenode*Front; Queuenode*rear;}; typedefstructNode2 Queue; Queue Initqueue ()//Initialize Queue{Queue Q; Q.front= (Queuenode *) malloc (sizeof(Queuenode)); Q.front->next=NULL; Q.rear=Q.front; return(Q);} Queue Inserq (Queue Q,CharX//x into the queue{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)//out Queue{ inti=t++, J; Queuenode*p; Chary; if(q.front==q.rear) {printf ("team listed, unable to get out of the queue! ");//determine if the queue is empty return(Q); } P=q.front->Next; Y=q.front->next->data;//assigning elements in a queue to YQ.front->next=p->Next; if(p==q.rear) Q.rear=Q.front; Str[i]=y;//storing single charactersSt[k]=i;//Storage location if(y==' '); if(y=='*'|| y=='|') { //if (y== ' * ')//str[i]=y; if(str[0]!=null)//if the array str is not NULL, the outputPrint (0, str[0]); T=0; //continue; } /*if ((y>= ' A ' &&y<= ' Z ') | | (y>= ' A ' &&y<= ' Z ')) Use ASCII to determine if Y is a letter and stored in the array str {str[i]=y; }*/k++; Free (p); returnQ;}voidPrint (intIChary);//call function to judge and outputMain () {Charx, y; Queue p,q; P=Initqueue (); printf ("Please enter normal type:"); while(SCANF ("%c", &x) = =1&&x!='\ n')//the method of the great God, the oxp=Inserq (p,x); Q=p; while(p.front!=p.rear) P=Deleteq (P); printf ("\ n The program was developed by Slag, not one of the group's representatives, thank you for using my program! \ n");}voidPrint (intICharY//call function to judge and output{a=st[i+1]+1; if(y=='|'|| y=='*') {k--; return; } if(str[i]!='|') A=t1++; if(str[i+1]=='*') {printf ("f (%d,%c) =%d\n"I'~', K); printf ("f (%d,%c) =%d\n", k,y,k); printf ("f (%d,%c) =%d\n"K'~', a); } Elseprintf ("f (%d,%c) =%d\n", i,y,st[i+1]); if(i<t) Print (i+1, str[i+1]); memset (str,0, N);//clears all elements in the array str}
Construction and identification of finite automata 3