Q2 V 1
Q2 V 1
h>
#include<stdlib.h>
struct node{
int st;
struct node * link;
};
struct node1
{
int nst[20];
};
int noalpha,nostate,start,nofinal,notransitions;
char alphabets[20];
int finalstate[20];
struct node * tranition[20][20]={NULL}; //Linked List
struct node1 hash[20];
int set[20];
int complete;
int findalpha(char c)
{
for(int i=0;i<noalpha;i++)
{
if(alphabets[i]==c)
{
return i;
}
}
return 999;
}
}
complete++;
hash[complete]=newstate;
return 1;
}
int main()
{
struct node *temp;
struct node1 newstate={0},tempstate={0};
//initialising hash
//first node1
for(int i=0;i<20;i++)
{
for(int j=0;j<20;j++)
{
hash[i].nst[j]=0;
}
}
//difficult part
complete=-1;
int i=-1;
printf("\nEquivalent DFA .... \n");
printf(" ...................... \n");
printf("Trnsitions of DFA\n");
//second node1 = newstate, 3rd =tempsate init with {0} in main
newstate.nst[start]=start;
insertstate(newstate);
//while loop
while (i!=complete)
{
i++;
newstate=hash[i];
//loops
for(int k=0;k<noalpha;k++)
{
int c=0;
for(int j=1;j<=nostate;j++)
{
//int array
set[j]=0;
}
for(int j=1;j<=nostate;j++)
{
int l=newstate.nst[j];
if(l!=0)
{
//node pointer in main
temp=tranition[l][k];
while (temp!=NULL)
{
if(set[temp->st]==0)
{
c++;
set[temp->st]=temp->st;
}
temp=temp->link;
}
}
}
printf("\n");
if(c!=0)
{
for(int m=1;m<=nostate;m++)
{
tempstate.nst[m]=set[m];
}
insertstate(tempstate);
printstate(newstate);
printf("%c\t",alphabets[k]);
printstate(tempstate);
printf("\n");
}
else
{
printstate(newstate);
printf("%c\t",alphabets[k]);
//printstate(tempstate);
printf("NULL\n");
}
}
}