6.26.2010

e-CLOSURE

#include
#include
#include
#include
char ttable[30][10][10];
int stack[30],top=-1;
void eclosure(int start,int end,int *closure)
{
while(top!=-1)
{
for(int i=start;i<=end;i++)
{
if(strchr(ttable[stack[top]][i],'e')!=NULL)
{

if(closure[i]==44)
{
top++;
stack[top]=i;
closure[i]=i;
i=start;
}
}
}
top--;
}
return;
}
void main()
{
clrscr();
int sstate,estate,start,end;
char in[30];
fstream p;
p.open("input.txt",ios::in); //input of form state state transition
p>>start>>end;
p>>sstate>>estate>>in;
while(p.eof()!=1)
{
strcat(ttable[sstate][estate],in);
p>>sstate>>estate>>in;
}
int n;
cout<<"Enter no. of states: ";
cin>>n;
int closure[10]={44,44,44,44,44,44,44,44,44,44},j=1;
cout<<"Enter states: ";
while(j<=n)
{
cin>>sstate;
stack[++top]=sstate;
closure[sstate]=sstate;
j++;
}
eclosure(start,end,closure);
cout<<"closure set is: ";
for(int i=0;i<10;i++)
{
if(closure[i]!=44)
cout< }
getch();
return;
}

No comments: