Circular Queue
Circular Queue
Circular Queue
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 deque()
{
if (isEmpty() == 1)
{
printf("\nQueue Underflow");
return;
}
printf("\nDeleted Element: %d", queue[front]);
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()
{
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
Enter Element: 45
1.Enque
2.Deque
3.Display
4.Peek
5.Exit
Enter Element: 67
1.Enque
2.Deque
3.Display
4.Peek
5.Exit
1.Enque
2.Deque
3.Display
4.Peek
5.Exit
Queue: 67
1.Enque
2.Deque
3.Display
4.Peek
5.Exit