Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node *next;
- };
- void insertion(struct node *f,struct node*r,int vv);
- void display(struct node *f);
- int main()
- {
- int v,c;
- struct node *front,*rear;
- front=(struct node*)malloc(1*sizeof(struct node));
- rear=(struct node*)malloc(1*sizeof(struct node));
- front->data=0;
- front->next=NULL;
- rear->data=0;
- rear->next=NULL;
- while(1)
- {
- printf("\n----- MENU -----\n");
- printf("\n----- Press 1 for insertion -----\n");
- printf("\n----- Press 3 for display -----\n");
- printf("\n----- Press 0 for quit -----\n");
- printf("\n Enter Your Choice \n");
- scanf("%d",&c);
- switch(c)
- {
- case 0:exit(0);
- break;
- case 1:
- printf("\n Choice=insertion \n");
- printf("Enter New value \n");
- scanf("%d",&v);
- insertion(front,rear,v);
- break;
- case 3:printf("\n Choice=Display \n");
- if(front->next!=NULL)
- display(front);
- else
- printf("\n The queue is Empty \n");
- break;
- default:printf("\n Wrong choice\n\n");
- break;
- }
- }
- }
- void insertion(struct node *f,struct node*r,int vv)
- {
- struct node *temp;
- temp=(struct node*)malloc(1*sizeof(struct node));
- temp->data=vv;
- temp->next=NULL;
- if(f->next==NULL)
- {
- f->next=temp;
- r->next=temp;
- }
- else
- {
- r->next->next=temp;
- r->next=temp;
- }
- }
- void display(struct node *f)
- {
- while(f->next!=NULL)
- {
- printf("\t %d",f->next->data);
- f=f->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement