Roll no: 18
Name: Sharayu Sandeep Kulkarni
#include<stdio.h>
#define MAX 6
int queue[MAX];
int front=-1;
int rear=-1;
void enqueue(int element) {
if(front==-1 && rear==-1) {
front = 0;
rear=0;
queue[rear]=element;
else if ((rear+1)%MAX==front) {
printf("Queue if overflow...\n");
else{
rear=(rear+1)%MAX;
queue[rear]=element;
void dequeue() {
if (front==-1 && rear==-1) {
printf("Queue if underflow...\n");
else if (front==rear) {
printf("The dequeued element is %d\n", queue [front]);
front=-1;
rear=-1;
else{
printf("The dequeued element is %d\n", queue[front]);
front=(front+1)%MAX;
void display() {
int i= front;
if (front==-1 && rear==-1) {
printf("Queue is empty...\n");
else{
printf("Elements in the queue are:\n");
while(i!=rear) {
printf("%d\t", queue[i]);
i=(i=1) % MAX;
printf("%d\n", queue[rear]);
}
}
int main(){
int choice=1, x;
printf("Press 1: Insert an element\n");
printf("Press 2: Delete an element\n");
printf("Press 3: Display an elements\n");
printf("Press 4: Exit\n");
while(choice!=0) {
printf("\nEnter your choice:");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the element which is to be inserted:");
scanf("%d", &x);
enqueue(x);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
printf("Exiting...\n");
break;
default:
printf("Wrong choice... Enter the correct choice\n");
return 0;
Output
Press 1: Insert an element
Press 2: Delete an element
Press 3: Display an elements
Press4: Exit
Enter your choice:1
Enter the element which is to be inserted:20
Enter your choice:1
Enter the element which is to be inserted:40
Enter your choice:1
Enter the element which is to be inserted:80
Enter your choice:1
Elements in queue are:
20 40 80
Enter your choice:2
The dequeued element is:20
Enter your choice:3
Enter the element which is to be inserted:20
Elements in queue are:
40 80
Enter your choice:4
Exiting…
===Code Execution Successful===