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 2 for deletion\n");
- printf("\n Press 3 for display\n");
- printf("\n Press 0 for quite\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("\n Enter new value \n");
- scanf("%d",&v);
- insertion(front,rear,v);
- break;
- case 3:printf("\nchoice = display\n");
- if(front->next!=NULL)
- display(front);
- else
- printf("\nThe queue is empty\n");
- break;
- default: printf("\n Wrong position\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