can anyone please point out what is wrong with my seeForward function? My program run fine with the option 2 ... however,, seeforward isn't working .... thx
# include "Name.h"
struct Node
{
Name name;
Node *link;
};
typedef Node* NodePtr;
void head_insert(NodePtr& head, Name* inName);
void output(NodePtr head);
void seeForward(NodePtr head);
int main()
{
Name *n;
NodePtr head= new Node;
int id;
string lastName, firstName, phone;
double amt;
ifstream reader;
reader.open("names.txt");
if(reader.fail())
{
cout<<"file not exist"<<endl;
}
reader>>id>>lastName>>firstName>>phone>>amt;
//n = new Name(id, lastName, firstName, phone, amt);
//head->name = *n;
head->name= *(new Name(id, lastName, firstName, phone, amt));
head->link= NULL;
while(reader>>id>>lastName>>firstName>>phone>>amt)
{
n = new Name(id, lastName, firstName, phone, amt);
head_insert(head, new Name(id, lastName, firstName, phone, amt));
//head_insert(head, n);
}
int option;
cout<<"Would you like to see the data forward or backward? (1.forward 2.backward"<<endl;
cin>>option;
if(option==2)
{
output(head);
}
else if(option==1)
{
seeForward(head);
}
return 0;
}
void seeForward(NodePtr head)
{
if(head= NULL)
{
}
else
{
seeForward(head->link);
(head->name).output();
}
}
void head_insert(NodePtr& head, Name* inName)
{
NodePtr temp_ptr;
temp_ptr = new Node;
temp_ptr->name= *inName;
temp_ptr->link= head;
head = temp_ptr;
}
void output(NodePtr head)
{
while(head!=NULL)
{
(head->name).output();
head= head->link;
}
}