Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node
- {
- int id;
- struct node *next,*prev;
- }*start=NULL,*end=NULL,*current;
- int co,i;
- void cre()
- {
- struct node *n;
- if(start==NULL)
- {
- printf("\nEnter Value:");
- n=(struct node*)malloc(1*sizeof(struct node));
- n->next=NULL;
- n->prev=NULL;
- scanf("%d",&n->id);
- start=n;
- end=n;
- current=n;
- co++;
- }
- else
- {
- printf("\nEnter Value:");
- n=(struct node*)malloc(1*sizeof(struct node));
- n->next=NULL;
- n->prev=NULL;
- scanf("%d",&n->id);
- current->next=n;
- n->prev=current;
- end=n;
- current=n;
- co++;
- }
- }
- void del()
- {
- if(co==1)
- {
- start=NULL;
- end=NULL;
- }
- if(start==NULL && end==NULL)
- {
- printf("\nQueue is Empty.\n");
- }
- else
- {
- struct node *c,*t;
- c=start;
- t=c->next;
- t->prev=NULL;
- start=t;
- co--;
- }
- }
- void dis()
- {
- if(start==NULL && end==NULL)
- {
- printf("\nQueue is Empty.\n");
- }
- else
- {
- struct node *c;
- c=start;
- while(c!=NULL)
- {
- printf("%d-->",c->id);
- c=c->next;
- }
- printf("NULL\n");
- printf("Front : %d Rear : %d\n",start->id,end->id);
- }
- }
- int main()
- {
- int x;
- printf("Enter the value of Queue\n");
- scanf("%d",&i);
- while(1)
- {
- printf("1.Ins, 2.Del,3.Dis\n");
- scanf("%d",&x);
- switch(x)
- {
- case 1:
- {
- if(co==i)
- {
- printf("Queue is Full.\n");
- break;
- }
- else
- {
- cre();
- break;
- }
- }
- case 2:
- {
- del();
- break;
- }
- case 3:
- {
- dis();
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement