#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node{
int data;
node *next;
};
class Linklist{
node *ptr,*save, *head, *tail;
public:
void ncreate();
void display();
void insert();
};
void Linklist:: ncreate()
{
while(1)
{
ptr = new node;
cout<<"enter info:";
cin>>ptr->data;
if(ptr->data==-999)
{
return;
}
if(head==NULL)
{
head=ptr;
tail=ptr;
}
else
{
tail->next=ptr;
tail=ptr;
}
}
}
void Linklist:: display()
{
ptr=head;
cout<<"\n \n list is :";
while(ptr!= NULL)
{
cout<<ptr->data;
ptr=ptr->next;
}
}
void Linklist:: insert()
{
int data,flag=0;
ptr= new node;
cout<<"enter the data to be insert: "<<endl;
cin>>ptr->data;
cout<<"enter the node after which data has to be insert:"<<endl;
cin>>data;
save=head;
while(save!= NULL)
{
if(save->data==data)
{
display();
ptr->next=save->next;
save->next=ptr;
flag = 1;
break;
}
save=save->next;
}
if(flag=0)
cout<<"node not found"<<endl;
}
void main()
{ Linklist list;
int ch,data;
do{
cout<<"\n main menu:";
cout<<"\n1.create:";
cout<<"\n2.display:";
cout<<"\n3.insert:";
cout<<"\n4.exit:";
cout<<"\n\n enter choice:";
cin>>ch;
switch(ch)
{
case 1:
list.ncreate();
break;
case 2:
list.display();
break;
case 3:
list.insert();
break;
case 4:exit(0);
}
}while(ch!= 4);
getch();
}
Insert Function is not working..please tell me the error..