-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular.cpp
More file actions
81 lines (73 loc) · 1.78 KB
/
circular.cpp
File metadata and controls
81 lines (73 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
using namespace std;
class CircularQueue {
int* queue;
int front,rear,maxsize,count;
public:
CircularQueue(int size){
maxsize=size;
queue = new int[size];
front=rear=count=0;
}
void placeOrder(int orderID){
if(count==maxsize){
cout<<"order is full\n";
return;
}
queue[rear]=orderID;
rear=(rear+1)%maxsize;
count++;
cout << "Order " << orderID << " placed successfully.\n";
}
void serveOrder(){
if(count==0){
cout<<"No order t serve:-";
return;
}
cout<<"order"<<queue[front]<<" served\n";
front=(front+1) % maxsize;
count--;
}
void displayOrders(){
if(count==0){
cout<<"No order currently..\n";
return;
}
cout<<"orders:-";
for(int i=0;i<count;i++){
int index = (front+i) % maxsize;
cout<<queue[index]<<" ";
}
cout<<endl;
}
};
int main() {
int m;
cout << "Enter maximum number of orders (M): ";
cin >> m;
CircularQueue q(m);
int choice, orderID;
do {
cout << "\n1. Place Order\n2. Serve Order\n3. Display Orders\n4. Exit\nEnter choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter Order ID: ";
cin >> orderID;
q.placeOrder(orderID);
break;
case 2:
q.serveOrder();
break;
case 3:
q.displayOrders();
break;
case 4:
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice!\n";
}
} while (choice != 4);
return 0;
}