typedef struct linkedlist
{
int rollno;
char name[20];
char branch[20];
int marks;
char remarks[20];
struct linkedlist *next;
}stu_t;
stu_t *insert(stu_t *);
stu_t *delete(stu_t *);
stu_t *update(stu_t *);
void *display(stu_t *);
main()
{
int option,status;
stu_t *head;
head=(stu_t *)malloc(sizeof(stu_t));
while(1)
{
puts("enter the option 1: insert 2:delete 3:update 4:sort 5:display 6:search 7:exit");
scanf("%d",&option);
switch(option)
{
case 1:
puts("enter roll no,name,branch,marks,remarks");
head=insert(head);
/* if(status==0)
printf("operation is success");
else
printf("operation is denied");*/
break;
case 2:
head=delete(head);
break;
case 3:
head=update(head);
break;
case 5:
display(head);
break;
case 6:
exit();
}
}
}
stu_t *insert(stu_t *head)
{
int option,b4number;
char value='y';
stu_t *new,*temp,*list;
list=head;
temp=head;
puts("enter the option 1:bottom 2:middle 3:top");
scanf("%d",&option);
switch(option)
{
case 1:
while(value=='y')
{
printf("enter the details");
scanf("%d%s%s%d%s",&list->rollno,list->name,list->branch,&list->marks,list->remarks);
new=(stu_t *)malloc(sizeof(stu_t));
list->next=new;
list=new;
puts("enter the option you want to add another record y:yes n:no");
__fpurge(stdin);
scanf("%c",&value);
}
if(value!='y')
list->next=0;
return head;
case 2:
while(value=='y')
{
puts("enter the position where u want to enter");
scanf("%d",&b4number);
puts("enter the new fields");
new=(stu_t *)malloc(sizeof(stu_t));
scanf("%d%s%s%d%s",&new->rollno,new->name,new->branch,&new->marks,new->remarks);
while(temp->next)
{
if(temp->rollno==b4number)
{
new->next=temp->next;
temp->next=new;
}
temp=temp->next;
}
puts("if you want ot add another option please press 'y'");
__fpurge(stdin);
scanf("%c",&value);
}
case 3:
while(value=='y')
{
puts("enter the fields");
new=(stu_t *)malloc(sizeof(stu_t));
scanf("%d%s%s%d%s",&new->rollno,new->name,new->branch,&new->marks,new->remarks);
new->next=head;
head=new;
puts("if you want ot add another option please press 'y'");
__fpurge(stdin);
scanf("%c",&value);
}
return head;
}
}
stu_t *delete(stu_t *head)
{
int i,option,rollno1;
stu_t *temp;
temp=head;
puts("from where you want to delete 1:top 2:middle 3:bottom");
scanf("%d",&option);
switch(option)
{
case 1:
head=head->next;
return head;
case 2:
puts("plz enter the rollno u want to delete");
scanf("%d",&rollno1);
while(temp->next)
{
if(temp->next->rollno==rollno1)
{
temp->next=temp->next->next;
}
temp=temp->next;
}
return head;
case 3:
while(temp->next)
{
if(temp->next->next==0)
{
temp->next=0;
return head;
}
temp=temp->next;
}
}
}
stu_t *update(stu_t *head)
{
int rollno1;
stu_t *temp;
temp=head;
puts("enter the old roll no of student to modify the details");
scanf("%d",&rollno1);
while(temp->next)
{
if(temp->rollno==rollno1)
{
puts("now enter the new values of student");
scanf("%d%s%s%d%s",&temp->rollno,temp->name,temp->branch,&temp->marks,temp->remarks);
}
temp=temp->next;
}
return head;
}
void *display(stu_t *head)
{
while(head->next!=0)
{
printf("%d\t%s\t%s\t%d\t%s\n",head->rollno,head->name,head->branch,head->marks,head->remarks);
head=head->next;
}
}
