Ex.No:9 LINKED LIST IMPLEMENTATION-QUEUE PROGRAM #include<stdio.h> #include #include<stdlib.h> struct queue { int data; struct queue *next; }; struct queue *head,*temp; void enqueue() { struct queue *enqueue; enqueue=(struct queue*)malloc(sizeof(struct queue)); printf("\nenter the data..."); scanf("%d",&enqueue->data); if(head==NULL) { head=enqueue; head->next=NULL; temp=enqueue; } else { temp->next=enqueue; enqueue->next=NULL; temp=enqueue; } } void dequeue() { struct queue *dequeue; int found=0; if(head==NULL) { printf("\ncreate the queue first....."); } else { head=head->next; found=1; }
if(found==1) printf("\nthe element is dequeueed..."); } void modify() { struct queue *mod,*data; int x,num,no; printf("\nenter the number to be modify...."); scanf("%d",&no); for(mod=head;mod!=NULL;mod=mod->next) { if(mod->data==no) { printf("\nenter the new number...."); scanf("%d",&num); mod->data=num; x=1; } } if(x==1) printf("\nthe number is modified..."); else printf("Element does not exist\n"); } void disp() { struct queue *disp; if(head==NULL) printf("\nthe queue is empty.."); else { for(disp=head;disp!=NULL;disp=disp->next) printf("%u\t%d\t%u\n",disp,disp->data,disp->data); } } void main() { int ch; char a='y'; clrscr(); printf("1.enqueue\t2.dequeue\t3.display\t4.modify\t5.exit\n"); do { printf("\nenter the choice......");
scanf("%d",&ch); switch(ch) { case 1: enqueue(); break; case 2: dequeue(); break; case 3: disp(); break; case 4: modify(); break; case 5: exit(0); break; default: printf("\nenter the correct choice."); } printf("do u want to continue.....(y/n):"); a=getche(); } while(a=='y'); getch(); }