shwetanshu
Cyborg Agent
Can anyone tell me the program for DELETION FROM THE END IN LINKED LIST DYNAMICALLY ???? I need it urgently, since day after tomorrow is my board practical. Here's the program for DELETION FROM THE BEGINING, but i m not able to modify it for DELETION from THE END
#include<iostream.h>
#include<conio.h>
#include<stddef.h>
#include<process.h>
struct node
{
int info;
node *next;
}*start,*newptr,*save,*ptr,*rear;
node *create_new_node(int);
void delnode();
void insert(node*);
void display(node*);
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');
}
node *create_new_node(int n)
{
ptr=new node;
ptr->info=n;
ptr->next=NULL;
return ptr;
}
void insert(node *np)
{
if(start==NULL)
{
start=np;
rear=np;
}
else
{
rear->next=np;
rear=np;
}
}
void display(node *np)
{
while(np!=NULL)
{
cout<<np->info<<" -> ";
np=np->next;
}
cout<<"!!!\n";
}
void delnode()
{
if(start==NULL)
cout<<"\n\n UNDERFLOW";
else
{
ptr=start;
start=start->next;
delete ptr;
}
}