Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<malloc.h>
- #include<string.h>
- struct student
- {
- char name[10];
- int m1;
- int m2;
- struct student *llink;
- struct student *rlink;
- };
- struct student * addelement(struct student *,char name[],int,int,int,int);
- void display( struct student *,char name[]);
- int main()
- {
- int num,i,m1,m2;
- struct student *head;
- head=NULL;
- char name[10];
- printf("\n Enter the number of students data to be entered :");
- scanf("%d",&num);
- for(i=1;i<=num;i++)
- {
- printf("Enter the name of the student :");
- scanf("%s",name);
- printf("\n Enter the marks in maths :");
- scanf("%d",&m1);
- printf("\n Enter the marks in science : ");
- scanf("%d",&m2);
- head=addelement(head,name,m1,m2,i,num);
- }
- printf("\n Enter the student name to be searched : ");
- scanf("%s",name);
- display(head,name);
- }
- struct student * addelement(struct student *head,char name[10],int m1,int m2,int i,int num)
- {
- struct student *newnode;
- newnode=(struct student *)malloc(sizeof(struct student));
- strcpy(newnode->name,name);
- newnode->m1=m1;
- newnode->m2=m2;
- if(i==num)
- {
- newnode->llink=NULL;
- newnode->rlink=head;
- head->llink=newnode;
- return newnode;
- }
- else if(head==NULL)
- {
- newnode->rlink=NULL;
- newnode->llink=NULL;
- return newnode;
- }
- else
- {
- head->llink=newnode;
- newnode->rlink=head;
- return newnode;
- }
- }
- void display(struct student *p3,char name[10])
- {
- struct student *temp;
- temp=p3;
- int flag=0;
- if(p3==NULL)
- {
- printf("\n The list is empty \n");
- }
- while(p3!=NULL)
- {
- printf("\n Student Name: %s, Maths Marks: %d,Science Marks: %d",p3->name,p3->m1,p3->m2);
- if(p3->m1>=90 && p3->m2>=90)
- {
- printf("\n Student Name: %s, Maths Marks: %d,Science Marks: %d",p3->name,p3->m1,p3->m2);
- p3=p3->rlink;
- }
- else
- {
- p3=p3->rlink;
- }
- }
- p3=temp;
- while(p3!=NULL)
- {
- if(strcmp(p3->name,name)==0)
- {
- flag=1;
- break;
- }
- else
- {
- p3=p3->rlink;
- }
- }
- if(flag==1)
- {
- printf("\n The student information exists in the database \n ");
- }
- else
- {
- printf("\n The student information does not exist in the database \n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement