error in debugging in my code (Help)

this is my code for turing machine and after i make the input(s) it stop working

#include <iostream>
#include<string.h>
using namespace std;
typedef struct Node
{
char data;
Node *next;
Node *prev;
}node;
typedef struct trans
{
int CState;
char CSymbol;
int NState;
char NSymbol;
char Move;
}trans;
node *L=NULL;
void DLLinsert(char x)
{node *SV=new node;
node *p,*q;
p=L;q=L;
SV->data=x;
if(L==NULL)
{
SV->next=NULL;
SV->prev=NULL;
L=SV;
}
else
{
while(p->next!=NULL)
{
p=p->next;
}
SV->prev=p;
SV->next=NULL;
p->next=SV;
L=q;
}}
int DLLPrint()
{
node *p;
p=L;
if(p==NULL){return 0;}
else{
while(p!=NULL)
{ cout<<p->data;
p=p->next; }
cout<<endl;}
return 1;}
int TMSolve(int k)
{
int state=0,i,position;
string tape;
node *p;
p=L;
trans *Trs=new trans[k];
for(i=0;i<k;i++)
{
cout<<"Enter transition"<<i+1<<endl;
cout<<"Enter current state:";cin>>Trs[i].CState;
cout<<"Enter current symbol:";cin>>Trs[i].CSymbol;
cout<<"Enter next state:";cin>>Trs[i].NState;
cout<<"Enter replacing symbol:";cin>>Trs[i].NSymbol;
cout<<"Enter moving step:";cin>>Trs[i].Move;
}
cout<<"Enter tape:";cin>>tape;
char *tape2=new char[80];
strcpy(tape2,tape.c_str());
for(i=tape.length();i<80;i++)
{
tape2[i]='#';
}
for(i=0;i<80;i++)
{
DLLinsert(tape2[i]);
}
cout<<"Enter head position:";cin>>position;
for(i=1;i<position;i++)
{
p=p->next;
}
while(p->next!=NULL)
{
for(i=0;i<k;i++)
{
if(Trs[i].CState==state&&Trs[i].CSymbol==p->data)
{
p->data=Trs[i].NSymbol;
state=Trs[i].NState;
if(Trs[i].Move=='r'||Trs[i].Move=='R')
{
if(p->next==NULL){return 0;}
p=p->next;
}
if(Trs[i].Move=='l'||Trs[i].Move=='L')
{
if(p->prev==NULL){return 0;}
p=p->prev;
}
if(Trs[i].Move=='y'||Trs[i].Move=='Y')
{
cout<<endl<<"accepted"<<endl;
return 1;
}
if(Trs[i].Move=='n'||Trs[i].Move=='N')
{
cout<<endl<<"refused"<<endl;
return 1;
}
}
}}
return 0;
}

int main()
{
int x,y,k,i;
cout<<"enter the number of states:";cin>>x;
cout<<"Enter the number of alphabet:";cin>>y;
char *A=new char[y];
int *St=new int[x];
for(i=1;i<y+1;i++)
{
cout<<"enter alphabet"<<i<<":";
cin>>A[i-1];
}
for(i=0;i<x;i++)
{
St[i]=i;
}
k=x*y;
TMSolve(k);
cout<<"Final configuration:";DLLPrint();
return 0;
}
any help??!!!
and make sure your code is [code]between code tags [/code] so that it has syntax highlighting and line numbers, as well as proper indentation.
http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.