Aug 18, 2013 at 4:05pm UTC
hey I compiled this program.but i got an error "segmentation dumped".Can anyone plz explain me the error in this
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int ns;
int l;
string k[1000];
int count=0;
class genlistnode
{
// friend class genlist;
public:
int flag;
string atom;
genlistnode *next,*down;
};
genlistnode* makelist();
int main()
{
string s;
cout<<"enter the string:";
getline (cin,s);
cout<<s<<endl;
int l=s.length();
string temp;
for (int i=0;i<l;i++)
{
if(s[i]==' ')
{
k[count]=temp;
temp="";
count=count+1;
}
else
{
temp=temp+s[i];
}
}
k[count]=temp;
count++;
cout<<"\n"<<count<<"\n";
for (int i=0;i<count;i++)
{
cout<<k[i]<<"\n";
}
genlistnode* result;
result=makelist();
}
int q=0;
genlistnode* makelist()
{
genlistnode *head;
genlistnode *p;
cout<<"\n"<<head;
head=NULL;
while(q!=count)
{
if(k[q]=="(")
{
if(head!=NULL){
cout<<k[q]<<count<<"done \n";
genlistnode *l;
l->next=NULL;
p->next=l;
p=l;
l->flag=0;
l->down=makelist();
}
else
{
cout<<"Hi";
genlistnode *l;
p=l;
head=l;
head->next=NULL;
head->flag=0;
head->down=makelist();
}
}
if(k[q]==")")
return head;
if((k[q]!=")")&& (k[q]!="("))
{
if(head!=NULL)
{
genlistnode *l=new genlistnode;
l->flag=1;
l->atom=k[q];
l->down=NULL;
l->next=NULL;
p->next=l;
p=l;
}
else
{
genlistnode *l=new genlistnode;
l->flag=1;
l->atom=k[q];
l->down=NULL;
l->next=NULL;
head=l;
p=l;
}
}
q++;
}
}
Aug 18, 2013 at 4:16pm UTC
It'll be easier to examine your code if you put it inside code tags and indent it properly.