};
void FA::RemoveRepeat(string &str)
{
string mid;
string::size_type idx;
string::iterator pos;
for(pos=str.begin();pos!=str.end();++pos)
{
idx=mid.find(*pos);
if(idx==string::npos)
mid+=*pos;
}
str=mid;
}
bool FA::IsInChangeTable(string str)
{
vector<ChangeTable>::iterator pos;
for(pos=changetable.begin();pos!=changetable.end();++pos)
if((*pos).state==str)
return 1;
return 0;
}
int FA::GetIndexofChangeTable()
{
int index;
for(index=0;index<changetable.size();++index)
if(changetable[index].flag==0)
return index;
return -1;
}
int FA::GetIndexofChangeTable(string str)
{
int index;
for(index=0;index<changetable.size();++index)
if(changetable[index].state==str)
return index;
return -1;
}
string FA::GetChangeState(char state1,char table)
{
string str;
vector<Transform>::iterator pos;
for(pos=fun.begin();pos!=fun.end();++pos)
if((*pos).state1==state1&&(*pos).letter==table)
str+=(*pos).state2;
RemoveRepeat(str);
return str;
}
void FA::input()
{
char ch;
Transform tran;
cout<<"input the set of state,ended with '#'"<<endl;
cin>>ch;
while(ch!='#')
{
state.push_back(ch);
cin>>ch;
}
cout<<"input the set of input's table,ended with '#'"<<endl;
cin>>ch;
while(ch!='#')
{
table.push_back(ch);
cin>>ch;
}
cout<<"input the transform of function,formation is state1 letter state1 "<<endl;
cout<<"ended with '# # #'"<<endl;
cin>>tran;
while(tran!='#')
{
fun.push_back(tran);
cin>>tran;
}
cout<<"input the state of Initlization table"<<endl;
cin>>q0;
cout<<"input the set of termination,ended with '#'"<<endl;
cin>>ch;
while(ch!='#')
{
Z.push_back(ch);
cin>>ch;
}
}
void FA::GetChangeTable()
{
ChangeTable ct,midct;
string str;
string mid;
queue<string> q;
vector<char>::iterator pos;
string::iterator p;
ct.state=string(1,q0); //从初始状态开始
ct.flag=0;
changetable.push_back(ct);
int index=GetIndexofChangeTable();
while(index!=-1)
{
changetable[index].flag=1;
str=changetable[index].state; //弹出状态