GTU DS Practical-5
Write a C program to implement Queue using arrays that perform the following
operations.
INSERT ,DELETE ,DISPLAY.
- #include<stdio.h>
- #include<stdlib.h>
- #define n 5
- int main()
- {
- int queue[n],ch=1,front=0,rear=0,i,j=1,x=n;
- printf("\n--------------------\n");
- printf("Queue using Array");
- printf("\n--------------------\n");
- printf("\n1.Insertion \n2.Deletion \n3.Display \n4.Exit\n");
- printf("\n--------------------\n");
- while(ch)
- {
- printf("\nEnter the Choice:");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:
- if(rear==x)
- printf("\n Queue is Full");
- else
- {
- printf("\n Enter no %d:",j++);
- scanf("%d",&queue[rear++]);
- }
- break;
- case 2:
- if(front==rear)
- {
- printf("\n Queue is empty");
- }
- else
- {
- printf("\n Deleted Element is %d",queue[front++]);
- x++;
- }
- break;
- case 3:
- printf("\n Queue Elements are:\n ");
- if(front==rear)
- printf("\n Queue is Empty");
- else
- {
- for(i=front; i<rear; i++)
- {
- printf("%d",queue[i]);
- printf("\n");
- }
- break;
- case 4:
- exit(0);
- default:
- printf("Wrong Choice: please see the options");
- }
- }
- }
- }
Comments
Post a Comment