循环队列的源文件测试代码
时间: 2023-09-03 11:06:55 浏览: 140
循环队列源代码
以下是循环队列的源文件测试代码,包括各种操作的测试:
```
#include <stdio.h>
#include <stdlib.h>
#include "circular_queue.h"
int main() {
int size = 5;
CircularQueue* queue = create_queue(size);
printf("Queue size: %d\n", get_size(queue));
printf("Is queue empty? %d\n", is_empty(queue));
printf("Is queue full? %d\n", is_full(queue));
printf("Enqueue 1\n");
enqueue(queue, 1);
printf("Enqueue 2\n");
enqueue(queue, 2);
printf("Enqueue 3\n");
enqueue(queue, 3);
printf("Enqueue 4\n");
enqueue(queue, 4);
printf("Enqueue 5\n");
enqueue(queue, 5);
printf("Queue size: %d\n", get_size(queue));
printf("Is queue empty? %d\n", is_empty(queue));
printf("Is queue full? %d\n", is_full(queue));
printf("Dequeuing...\n");
printf("%d\n", dequeue(queue));
printf("%d\n", dequeue(queue));
printf("%d\n", dequeue(queue));
printf("Enqueue 6\n");
enqueue(queue, 6);
printf("Enqueue 7\n");
enqueue(queue, 7);
printf("Queue size: %d\n", get_size(queue));
printf("Is queue empty? %d\n", is_empty(queue));
printf("Is queue full? %d\n", is_full(queue));
printf("Dequeuing...\n");
printf("%d\n", dequeue(queue));
printf("%d\n", dequeue(queue));
printf("%d\n", dequeue(queue));
printf("%d\n", dequeue(queue));
printf("%d\n", dequeue(queue));
printf("Is queue empty? %d\n", is_empty(queue));
printf("Is queue full? %d\n", is_full(queue));
printf("Freeing queue...\n");
free_queue(queue);
return 0;
}
```
阅读全文