content=//Program to demonstrate Deletion of an element in a Link List.
#include
#include
#include
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<<"enter the name and marks of three subjects of five children ";
for(int i=0;i<=4;i++)
{
if(start==NULL)
{
list=new abc;
cout<<"enter the details :";
cin>>list->n>>list->p>>list->c>>list->m;
start=list;
}
else
{
ptr=new abc;
cin>>ptr->n>>ptr->p>>ptr->c>>ptr->m;
list->next=ptr;
list=list->next;
} }
// delete the record whose name is entered
cout<<"\n enter the name whose record is to be delete \n";
cin>>nm;
ptr=start;
cout<<"\n the list is :\n";
prev=ptr;
while(ptr!=NULL)//1
{
if(strcmp(ptr->n,nm)==0)//3
{
flag='y';//4
cout<<"yes got the record ";//5
if (ptr==start)//6
start=ptr->next;//7
else
prev->next=ptr->next;//9
if(ptr->next==NULL)//10
prev->next=NULL;//11
}
prev=ptr;//12
ptr=ptr->next;//13
}//end of while
if(flag!='y')
{
cout<<"sorry no such name present \n";
c=4;
}
else
c=5;
//display all the records of the linked list
ptr=start;
cout<<"\n\n";
i=0;
cout<<"name percentage\n";
while(ptr!=NULL)
{ ++i;
cout<<"\n name :"<n;
cout<<" percent :"<<(ptr->p+ptr->c+ptr->m)/3;
ptr=ptr->next;
if (i==c)
break;
}
getch();
}
2007-01-19
01:50:02
·
1 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Software
explain me only the while statement along with the numbering of the lines
2007-01-19
01:50:52 ·
update #1