窗口排队管理系统c语言代码
时间: 2023-07-03 20:20:07 浏览: 67
C语言编写的银行排队系统
5星 · 资源好评率100%
好的,以下是一个简单的窗口排队管理系统的 C 语言代码示例:
```
#include <stdio.h>
#include <stdlib.h>
#define MAX_QUEUE_SIZE 100
typedef struct {
int window_number;
int customer_number;
} QueueEntry;
typedef struct {
QueueEntry entries[MAX_QUEUE_SIZE];
int front;
int rear;
} Queue;
void initialize_queue(Queue *q) {
q->front = 0;
q->rear = -1;
}
int is_queue_empty(Queue *q) {
return (q->rear < q->front);
}
int is_queue_full(Queue *q) {
return (q->rear == MAX_QUEUE_SIZE - 1);
}
void enqueue(Queue *q, QueueEntry e) {
if (is_queue_full(q)) {
printf("Error: Queue is full\n");
exit(EXIT_FAILURE);
}
q->rear++;
q->entries[q->rear] = e;
}
QueueEntry dequeue(Queue *q) {
if (is_queue_empty(q)) {
printf("Error: Queue is empty\n");
exit(EXIT_FAILURE);
}
QueueEntry e = q->entries[q->front];
q->front++;
return e;
}
void display_queue(Queue *q) {
int i;
printf("Window\tCustomer\n");
for (i = q->front; i <= q->rear; i++) {
printf("%d\t%d\n", q->entries[i].window_number, q->entries[i].customer_number);
}
}
int main() {
Queue q;
QueueEntry entry;
initialize_queue(&q);
entry.window_number = 1;
entry.customer_number = 100;
enqueue(&q, entry);
entry.window_number = 2;
entry.customer_number = 101;
enqueue(&q, entry);
entry.window_number = 3;
entry.customer_number = 102;
enqueue(&q, entry);
display_queue(&q);
dequeue(&q);
printf("\nAfter dequeue:\n");
display_queue(&q);
return 0;
}
```
这个示例程序定义了一个队列数据结构(使用结构体实现),以及一些常用的队列操作函数,例如“初始化队列”、“入队”、“出队”和“显示队列”。程序创建一个队列并将一些入队操作用于它,然后使用出队操作进行演示。
阅读全文