c语言银行排队系统带有vip功能代码
时间: 2024-12-12 07:23:27 浏览: 21
在编写C语言的银行排队系统并添加VIP功能时,我们需要创建几个主要的结构体来表示客户、普通队列和VIP队列,并定义函数来处理客户的加入、离开和服务顺序。由于这是一个复杂的示例,我将提供一个简化的伪代码框架,你可以根据需要进行扩展:
```c
#include <stdio.h>
#include <stdlib.h>
typedef struct Customer {
int id;
char priority; // 'P' for regular, 'V' for VIP
} Customer;
typedef struct QueueNode {
Customer customer;
struct QueueNode *next;
} QueueNode;
// Regular queue
QueueNode *regular_queue;
int regular_size;
// VIP queue
QueueNode *vip_queue;
int vip_size;
// Function to enqueue a customer (enqueue at the end)
void enqueue(Customer *customer, QueueNode **queue) {
QueueNode *new_node = (QueueNode*)malloc(sizeof(QueueNode));
new_node->customer = *customer;
new_node->next = NULL;
if (*queue == NULL) {
*queue = new_node;
} else {
QueueNode *temp = *queue;
while (temp->next != NULL) temp = temp->next;
temp->next = new_node;
}
}
// Function to check and serve customers based on priority
void serveCustomers() {
if (regular_queue && vip_queue) {
if (regular_size > 0 && vip_size == 0) {
QueueNode *current = regular_queue;
while (current != NULL) {
printf("Serving %d - Priority: %c\n", current->customer.id, current->customer.priority);
// Service logic here
current = current->next;
regular_size--;
}
} else if (vip_size > 0) {
QueueNode *current = vip_queue;
while (current != NULL) {
printf("Serving %d - Priority: %c\n", current->customer.id, current->customer.priority);
// Service logic here
current = current->next;
vip_size--;
}
}
}
}
int main() {
// Initialize queues
regular_queue = NULL;
regular_size = 0;
vip_queue = NULL;
vip_size = 0;
// Example usage
Customer regular = {1, 'P'};
Customer vip = {2, 'V'};
enqueue(®ular, ®ular_queue); // Enqueue regular
enqueue(&vip, &vip_queue); // Enqueue VIP
// Serve customers
serveCustomers();
return 0;
}
阅读全文