Shwetanshu,
1. In order to delete from the end, you need to create a bidirectional list. In struct node, add another variable node *prev. Go through your code and make sure you incorporate the new pointer in all your initializations and operations. Then, you can delete nodes from the end. (I am not going to give you detailed code, coz that will defeat the purpose of the learning process...)
2. Please indent your code - so hard to read, i had to cut and paste and indent myself before I would read...
For example,
void main()
{
clrscr();
start=NULL;
int inf;
char ch='y';
do
{
cout<<"\n\n Enter information for the new node : ";
cin>>inf;
newptr=create_new_node(inf);
if(newptr==NULL)
{
cout<<"\n\n Creating new node !!! Aborting....!!!!\n";
getch();
exit(0);
}
insert(newptr);
cout<<"\n\n Press Y to enter New Nodes, N to exit\n";
cin>>ch;
}while(ch=='Y'||ch=='y');
clrscr();
do
{
cout<<"\n\n The list now is : \n";
display(start);
getch();
cout<<"\n\n Want to delete first Node? (y/n) ...";
cin>>ch;
if(ch=='Y'||ch=='y')
delnode();
}while(ch=='y'||ch=='Y');
}
Best of luck for your boards practical
Arun
|