Nov 7, 2010 at 2:10am UTC
I am studying linked list... and my prog should display the first and last inputed data and the no. of times you inputed... the problem is... I can't seem to display the first data no matter what I do... please help...
#include <iostream>
#include <string>
using namespace std;
int operation(int);
struct linkedlist
{
char name[30];
char chose;
string temp;
linkedlist *next;
};//end struct
linkedlist *start;
int main()
{
operation(0);
return 0;
}//end main
int operation(int x)
{
linkedlist *ptr = new linkedlist();
cout << "Please input the name: " << endl;
cin >> ptr->name;
// the nxt line is supposed to store the first data in temp... then be displayed at the end...
while(ptr->temp==NULL)
{
ptr->temp = ptr->name;
}
start = ptr;
start->next = NULL;
cout << "Do you want to enter again? <Y/N>" << endl;
cin >> ptr->chose;
cout << endl << endl;
if(ptr->chose=='y'|| ptr->chose=='Y')
{
x++;
return operation(x++);
}
else
{
cout << ptr->temp << endl;
cout << ptr->name << endl;
cout << x << endl;
}
return 0;
}//end void