0% found this document useful (0 votes)
23 views4 pages

Circular Queue

Data structure Experiment

Uploaded by

batharva24comp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Circular Queue

Data structure Experiment

Uploaded by

batharva24comp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <stdio.

h>
#include <stdlib.h>
#define max 5
int queue[max];
int front = -1, rear = -1;

int isFull()
{
if ((rear + 1) % max < front)
return 1;
else
return 0;
}

int isEmpty()
{
if (front == -1)
return 1;
else
return 0;
}

void enque(int ele)


{
if (isFull() == 1)
{
printf("\nQueue Overflow");
return;
}
if (front == -1)
{
front = 0;
}
rear = (rear + 1) % max;
queue[rear] = ele;
}

void deque()
{
if (isEmpty() == 1)
{
printf("\nQueue Underflow");
return;
}
printf("\nDeleted Element: %d", queue[front]);

front = (front + 1) % max;


}

void peek()
{
if (isEmpty() == 1)
{
printf("\nQueue Underflow");
}
printf("\nPeek: %d", queue[front]);
}
void display()
{
int i = front;
printf("\nQueue: ");
while (i != rear)
{
printf("%d ", queue[i]);
i = (i + 1) % max;
}
printf("%d ", queue[rear]);
}

int main()
{

int choice, ele;


do
{
printf("\n1.Enque");
printf("\n2.Deque");
printf("\n3.Display");
printf("\n4.Peek");
printf("\n5.Exit");
printf("\nSelect the operation: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\nEnter Element: ");
scanf("%d", &ele);
enque(ele);
break;

case 2:
deque();
break;

case 3:
display();
break;

case 4:
peek();
break;
case 5:
exit(0);
break;
}
} while (choice != 6);

return 0;
}

Output:-

1.Enque

2.Deque

3.Display

4.Peek

5.Exit

Select the operation: 1

Enter Element: 45

1.Enque

2.Deque

3.Display

4.Peek

5.Exit

Select the operation: 1

Enter Element: 67

1.Enque

2.Deque

3.Display

4.Peek

5.Exit

Select the operation: 2


Deleted Element: 45

1.Enque

2.Deque

3.Display

4.Peek

5.Exit

Select the operation: 3

Queue: 67

1.Enque

2.Deque

3.Display

4.Peek

5.Exit

Select the operation: 5

You might also like