content=//Program to demonstrate Deletion of an element in a Link List.
#include%26lt;iostream.h%26gt;
#include%26lt;conio.h%26gt;
#include%26lt;string.h%26gt;
struct abc
{
char n[20];
int m;
int p;
int c;
abc *next;
};
void main()
{
clrscr();
int c=0,per;
abc *list,*start=NULL,*ptr,*prev;
char nm[20],flag;
cout%26lt;%26lt;"enter the name and marks of three subjects of five children ";
for(int i=0;i%26lt;=4;i++)
{
if(start==NULL)
{
list=new abc;
cout%26lt;%26lt;"enter the details :";
cin%26gt;%26gt;list-%26gt;n%26gt;%26gt;list-%26gt;p%26gt;%26gt;list-%26gt;c%26gt;%26gt;list-%26gt;...
start=list;
}
else
{
ptr=new abc;
cin%26gt;%26gt;ptr-%26gt;n%26gt;%26gt;ptr-%26gt;p%26gt;%26gt;ptr-%26gt;c%26gt;%26gt;ptr-%26gt;m;
list-%26gt;next=ptr;
list=list-%26gt;next;
} }
// delete the record whose name is entered
cout%26lt;%26lt;"\n enter the name whose record is to be delete \n";
cin%26gt;%26gt;nm;
ptr=start;
cout%26lt;%26lt;"\n the list is :\n";
prev=ptr;
while(ptr!=NULL)//1
{
if(strcmp(ptr-%26gt;n,nm)==0)//3
{
flag='y';//4
cout%26lt;%26lt;"yes got the record ";//5
if (ptr==start)//6
start=ptr-%26gt;next;//7
else
prev-%26gt;next=ptr-%26gt;next;//9
if(ptr-%26gt;next==NULL)//10
prev-%26gt;next=NULL;//11
}
prev=ptr;//12
ptr=ptr-%26gt;next;//13
}//end of while
if(flag!='y')
{
cout%26lt;%26lt;"sorry no such name present \n";
c=4;
}
else
c=5;
//display all the records of the linked list
ptr=start;
cout%26lt;%26lt;"\n\n";
i=0;
cout%26lt;%26lt;"name percentage\n";
while(ptr!=NULL)
{ ++i;
cout%26lt;%26lt;"\n name :"%26lt;%26lt;ptr-%26gt;n;
cout%26lt;%26lt;" percent :"%26lt;%26lt;(ptr-%26gt;p+ptr-%26gt;c+ptr-%26gt;m)/3;
ptr=ptr-%26gt;next;
if (i==c)
break;
}
getch();
}
Plz explain me with this....?
huh?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment