please guide me as what is the not working

its a menu driven program. the user enters 1 to insert element and 2 to display.
after I entered more than 1 element.and pressed 2 to display it only dislayed the first element.please help me with this. thanks...


#include<iostream>
using namespace std;
class link_list
{
int data;
link_list *next;
public:
link_list()
{
data = 0;
next = NULL;
}
link_list(int num)
{
data = num;
next = NULL;
}
~link_list(){}
void insert(link_list *node);
friend void display(link_list *);
};

void link_list::insert(link_list *node)
{
link_list *last ;
last = node;
while(last->next != NULL)// until next of last is not null
{

last->next = node; // next of last becomes equal to node
last = last->next;
// last jumps to next
}
}

void display(link_list *first)
{
link_list *traverse;
traverse=first;
while(traverse!=NULL)
{
cout<<traverse->data<<"-->";
traverse=traverse->next;
}
cout<<"NULL"<<endl;
}

int main()
{
char choice;
int num;

link_list *first;
link_list *node;
first = NULL;
cout<<"\n\n1->insert\n2->display\n3->exit\n\n";

link_list object ;
while(1)
{

cout<<"\nChoice : ";
do
{
cin>>choice;
}while(choice < '0' && choice >= '3' );
switch(choice)
{

case '1':
cout<<"\n\nEnter data : ";
cin>>num;
cout<<endl;
node = new link_list(num);
if (first == NULL)
{
first = node;
}
else
{
first->insert(node);
}
break;

case '2':
display(first);
cout<<endl;
break;

case '3':
exit(0);

default:
cout<<"\nInvalid entry\n";
continue;

}
}
system("pause");
return 0;
}


Topic archived. No new replies allowed.