#include
#include
#include

struct student{

int sno;
char sname[25];
int m1,m2,m3;
int tot;
float per;
struct student *next;
};
int main()
{
char cont='y',choice;
char sear[20];
int ch, i,nsno;
struct student *pp,*fp,*p,*pl,*np;

do
{
printf("\nI.creation");
printf("\n2.traversing the linked list ");
printf("\n3.locating the particular element");
printf("\n4.insertion");
printf("\n5.deletion");
printf("\n6.quit");
printf("\nenter your choice :");
scanf("%d",&ch);
switch(ch)

{
case 1:fp=p=pl=(struct student *)malloc(sizeof(struct student));
while(cont=='y')
{

printf("enter student no");
scanf("%d",&p->sno);
printf("enter student name:");
scanf("%s",&p->sname);
printf("enter student mark1");
scanf("%d",&p->m1);
printf("enter student mark2");
scanf("%d",&p->m2);
printf("enter student mark3");
scanf("%d*c",&p->m3);
(*p).tot=(*p).m1+(*p).m2+(*p).m3;
(*p).per=(float)(*p).tot/3.0;
printf("do you want continue(y/n) ");
fflush(stdin);
cont=getchar();
if(cont=='y')
p->next=(struct student *)malloc(sizeof(struct student));
else
p->next=(struct student *)0;
p=p->next;
}
break;
case 2:pl=fp;
printf("traversing the linked list");
while(pl!=(struct student *)0)
{
printf("student no:\n",&pl->sno);
printf("student name:%s\n",&pl->sname);
printf("mark1:%d\n",&pl->m1);
printf("mark2:%d\n",&pl->m2);
printf("mark3:%d\n",&pl->m2);
printf("total:%d\n",&pl->tot);
printf("average:%f\n",&pl->per);
getch();
pl=pl->next;
}
break;
case 3:pl=fp;
printf("enter name of student that you want to find out:");
scanf("%s",sear);
while(pl!=(struct student *)0)
{
i=strcmp(pl->sname,sear);
if(i==0)
{
printf("student no:%d\n",&pl->sno);
printf("student name:%s\n",&pl->sname);
printf("mark1:\n",&pl->m1);
printf("mark2:%d\n",&pl->m2);
printf("mark3:%d\n",&pl->m3);
printf("total:%d\n", &pl->tot);
printf("average:%f\n", &pl->per);
break;
}
else
pl=pl->next;
}
if(pl==0&&i!=0)
printf("\nname not found");
break;
case 4:
printf(" a) at the beginning...\n");
printf(" b) at the middle...\n");
printf(" c) at the end...\n");
printf("enter your choice ");
scanf("%*c%c",&choice);
switch(choice)
{
case 'a':p=(struct student *)malloc(sizeof(struct student));
printf("enter student number:");
scanf("%d",&p->sno);
printf("enter student name 0:");
scanf("%s",&p->sname);
printf("enter student mark1:");
scanf("%d",&p->m1);
printf("enter student mark2:");
scanf("%d",&p->m2);
printf("enter student mark3:");
scanf("%d*c",&p->m3);
(*p).tot=(*p).m1+(*p).m2+(*p).m3;
(*p).per=(float)(*p).tot/3.0;
p->next=fp;
fp=p;
break;
case 'b':pl=fp;
printf("after which student number do you want to insert");
scanf("%d",&nsno);
while(pl->sno!=nsno)
pl=pl->next;
np=pl->next;
p=(struct student *)malloc(sizeof(struct student));
pl->next=p;
printf("enter student number:");
scanf("%d",&p->sno);
printf("enter student mark1:");
scanf("%d",&p->m1);
printf("enter student mark2:");
scanf("%d",&p->m2);
printf("enter student mark3:");
scanf("%d*c",&p->m3);
(*p).tot=(*p).m1+(*p).m2+(*p).m3;
(*p).per=(float)(*p).tot/3.0;
p->next=np;
break;
case 'c':
pl=fp;
while(pl->next!=(struct student *)0)
pl=pl->next;
p=(struct student *)malloc(sizeof(struct student));
pl->next =p;
printf("enter student number:");
scanf("%d",&p->sno);
printf("enter student name:");
scanf("%s",&p->sname);
printf("enter student mark1:");
scanf("%d",&p->m1);
printf("enter student mark2:");
scanf("%d",&p->m2);
printf("enter student mark3:");
scanf("%d",&p->m3);
(*p).tot=(*p).m1+(*p).m2+(*p).m3;
(*p).per=(float)(*p).tot/3.0;
p->next=(struct student *)0;
break;


case 5:
printf("which student record u want to delete");
scanf("%d",&nsno);
if(fp=NULL)
{
printf("the stingy linked list is empty");
break;
}
pl=fp;
if(fp->sno==nsno)
{
fp=fp->next;
pl=fp;
break;
}
else

{
pl=fp;
while(pl->sno!=nsno)
{
pp=pl;
pl=pl->next;
}
pp->next=pl->next;
printf("record deleted");
break;
}
pl=fp;
/*check weather the record to be deleted is the last record*/
while(pl->next!=(struct student *)0)
pl=pl->next;
if(p->next==((struct student *)0)&&(pl->sno==nsno))
{
pl=pl->next-1;
pl->next=(struct student *)0;
printf("no:%d",pl->sno);
break;
}
else
{
printf("the given sn is not found\n");
break;
}


}



}
while(ch!=6);}