Hi there;
I was trying to build a DOS programme that helps you draw a state digram
of a Sequential State Machine. The application halts once I enter the codes, and I am clueless about where the error is. As much as I hate to send the whole code, I will do it anyway. Please guys any comment would help.......Thanks
Code:
#include <iostream>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int Max(list<int>values)
{
list<int>::iterator current = values.begin();
int high = *current++;
while (current != values.end())
{
if (*current > high)
{
high = *current;
}
current++;
}
return high;
}
int main()
{
list<int>OrgSeq;
int no_of_code;
//list<int>::iterator point;
cout<<"Enter the number of code: ";
cin>>no_of_code;
list<int>::iterator it=OrgSeq.begin();
list<int>::iterator that;
// User enter the original sequence in a list
for(int y=0; y<no_of_code; y++)
{
int k;
cout<<"Enter the next code (in Decimal): ";
cin>>k;
OrgSeq.push_back(k);
}
// The programme loops through all the states
for(int j=0; j<no_of_code; j++)
{
it++;
for(int i=0; i<=Max(OrgSeq); i++)
{
list<int>OrgSeq2(OrgSeq);
that=OrgSeq2.begin();
for(int s=j; s>=0; s++)
{
if(i==*it)
break;
list<int>cpyseq(OrgSeq);
that++;
list<int>::iterator iter = cpyseq.begin();
for(int L=0; L<=s; L++)
iter++;
cpyseq.insert(iter,i);
cpyseq.insert(iter,that,OrgSeq2.end());
cpyseq.erase(iter,cpyseq.end());
list<int>::iterator final=cpyseq.end();
for(int t=0; t<no_of_code; t++)
final--;
cpyseq.erase(cpyseq.begin(),final);
if( OrgSeq == cpyseq )
{
cout<<"State "<<j<<" goes back to state "<<s<<" by code "<<i<<endl;
break;
}
that--;
}
}
}
system("PAUSE");
return 0;
}