DSA_Practical 3
DSA_Practical 3
DSA_Practical 3
#include <iostream>
using namespace std;
bool isFull() {
return (rear + 1) % MAX_SIZE == front;
}
bool isEmpty()
{ return front == -1;
}
if (isEmpty()) {
front = rear = 0;
} else {
rear = (rear + 1) % MAX_SIZE;
}
return data;
}
void display() {
if (isEmpty()) {
cout << "Queue is empty!" << endl;
return;
}
private: int
queue[MAX_SIZE]; int
front, rear;
};
int main()
{ CircularQueue cq;
int choice, data;
while (true) {
cout << "\n1. Enqueue\n2. Dequeue\n3. Display\n4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter data to enqueue: ";
cin >> data;
cq.enqueue(data);
break; case 2:
data = cq.dequeue();
if (data != -1) {
cout << data << " dequeued.\n";
}
break;
case 3:
cq.display();
break; case 4:
exit(0);
default:
cout << "Invalid choice!" << endl;
}
}
return 0;
}
Output:-