int customerIDs[MAX_CUSTOMERS];
int front = -1;
int rear = -1;
void initializeQueue() {
front = -1;
rear = -1;
}int isFull() {
return rear == MAX_CUSTOMERS - 1;
}int isEmpty() {
return front == -1;
}int addCustomer(int customerID) {
if (isFull()) {
return 0;
}
if (isEmpty()) {
front = 0;
}
rear++;
customerIDs[rear] = customerID;
return 1;
}int processCustomer(int* customerID) {
if (isEmpty()) {
return 0;
}*customerID = customerIDs[front];
front++;
if (front > rear) {
front = rear = -1;
}
return 1;
}void displayQueue() {
if (isEmpty()) {
printf("Checkout queue is empty.\n");
return;
}
printf("Customers waiting in the checkout queue: ");
for (int i = front; i <= rear; i++) {
printf("%d ", customerIDs[i]);
}
printf("\n");
}int main() {
initializeQueue();
int option, customerID;
while (1) {
if (scanf("%d", &option) != 1)
break;
if (option == 1) {
if (scanf("%d", &customerID) != 1)
break;
if (addCustomer(customerID) == 0) {
printf("Checkout queue is full.\n");
} else {
printf("Customer ID %d joined the checkout queue.\n", customerID);
}
} else if (option == 2) {
if (processCustomer(&customerID) == 0) {
printf("Checkout queue is empty.\n");
} else {
printf("Processed Customer ID: %d\n", customerID);
}
}
else if (option == 3) {
displayQueue();
}
else if (option == 4) {
printf("Exiting Program\n");
break;
}
else {
printf("Invalid option.\n");
}
}
return 0;
}
| |