0% found this document useful (0 votes)
7 views2 pages

PRGM 14

The document contains a C++ program that implements circular queue operations using arrays. It includes functions for inserting, deleting, and displaying elements in the queue, along with a menu for user interaction. The program handles cases for queue overflow and underflow appropriately.

Uploaded by

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

PRGM 14

The document contains a C++ program that implements circular queue operations using arrays. It includes functions for inserting, deleting, and displaying elements in the queue, along with a menu for user interaction. The program handles cases for queue overflow and underflow appropriately.

Uploaded by

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

Program to implement circular cout << "The element deleted is " <<

operations using arrays. queue[front] << endl;

#include <iostream.h> if (front == rear)

#include <conio.h> {

#include <stdlib.h> front = -1;

#define SIZE 4 rear = -1;

int rear = -1, front = -1; }

int queue[10]; else

void insert() {

{ front = (front + 1) % SIZE;

if ((rear + 1) % SIZE == front) }

{ }

cout << "Queue Overflow" << endl; }

} void display()

else {

{ if (front == -1)

rear = (rear + 1) % SIZE; {

cout << "Enter the element to be cout << "Queue Empty" << endl;
inserted: ";
}
cin >> queue[rear];
else
if (front == -1)
{
{
cout << "Queue elements are:" <<
front = 0; endl;

} int count = (rear >= front) ? (rear - front


+ 1) : (SIZE - front + rear +
}
1);
}
for (int i = 0; i < count; i++)
void DeleteQ()
{
{
cout << queue[(front + i) % SIZE] << "\
if (front == -1)
t";
{
}
cout << "Queue Empty" << endl;
}
}
}
else
int main()
{
{
int ch;

while (1)

cout << "\nCIRCULAR QUEUE MENU" <<


endl;

cout << "1. Insert" << endl;

cout << "2. Delete" << endl;

cout << "3. Display" << endl;

cout << "4. Exit" << endl;

cout << "Enter your choice: ";

cin >> ch;

switch (ch)

case 1:

insert();

break;

case 2:

DeleteQ();

break;

case 3:

display();

break;

case 4:

exit(0);

default:

cout << "Invalid choice" << endl;

You might also like