Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- menu();
- add();
- addpos();
- search();
- searchpos();
- searchval();
- Delete();
- deletepos();
- deleteval();
- insertfirst();
- insertlast();
- display();
- typedef struct node
- {
- int a;
- char s[20];
- struct node *next;
- } node;
- node *head=NULL;
- int searchval()
- {
- int b,v;
- node *list=head;
- printf("Enter Your Age:");
- scanf("%d",&v);
- while(1)
- {
- if(list->a==v)
- {
- printf("Name:%s\n",list->s);
- printf("Age:%d\n",list->a);
- break;
- }
- list=list->next;
- }
- printf("\n1.Menu\n");
- printf("2.Exit\n");
- printf("Choose a Option:");
- scanf("%d",&b);
- switch(b)
- {
- case 1:
- {
- menu();
- break;
- }
- case 2:
- {
- exit(0);
- }
- default:
- {
- printf("You Choose Wrong Option!!\a\nPlease Choose Correct Option\n");
- menu();
- }
- }
- }
- int searchpos()
- {
- int p,v,b;
- node *list=head;
- printf("Enter Your Position:");
- scanf("%d",&p);
- if(p==1)
- {
- printf("Name:%s\n",list->s);
- printf("Age:%d\n\n",list->a);
- }
- else
- {
- p=p-2;
- while(p--)
- {
- list=list->next;
- }
- printf("Name:%s\n",list->next->s);
- printf("Age:%d\n",list->next->a);
- }
- printf("\n1.Menu\n");
- printf("2.Exit\n");
- printf("Choose a Option:");
- scanf("%d",&b);
- switch(b)
- {
- case 1:
- {
- menu();
- break;
- }
- case 2:
- {
- exit(0);
- }
- default:
- {
- printf("You Choose Wrong Option!!\a\nPlease Choose Correct Option\n");
- menu();
- }
- }
- }
- int search()
- {
- int b;
- printf("\n1.Search By position\n");
- printf("2.Search By Value\n");
- printf("3.Menu\n");
- printf("4.Exit\n");
- printf("Choose a Option");
- scanf("%d",&b);
- switch(b)
- {
- case 1:
- {
- searchpos();
- break;
- }
- case 2:
- {
- searchval();
- break;
- }
- case 3:
- {
- menu();
- break;
- }
- case 4:
- {
- exit(0);
- }
- default:
- {
- printf("You Choose Wrong Option!!\a\nPlease Choose Correct Option\n");
- search();
- }
- }
- }
- int deleteval()
- {
- int b,v;
- node *list=head,*temp;
- printf("Enter Your Value:");
- scanf("%d",&v);
- if(list->a==v)
- {
- head=list->next;
- free(list);
- }
- else
- {
- while(1)
- {
- if(list->next->a==v)
- {
- temp=list->next;
- break;
- }
- else
- {
- list=list->next;
- }
- }
- list->next=temp->next;
- free(temp);
- }
- printf("\n\n1.Menu\n");
- printf("2.Exit\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement