c语音设计一个只使用队头指针和计数器的顺序循环队列抽象数据类型。其中操作包括:初始化、入队列、出队列、判断队列是否非空
时间: 2024-05-08 13:17:58 浏览: 16
。好的,这是一个关于编程的问题。可以回答。这是一个只使用队头指针和计数器的顺序循环队列,抽象数据类型可以定义如下:
```
typedef struct {
int front; // 队头指针
int count; // 队列长度
TYPE data[MAXSIZE]; // 存储数据的数组
} CIRCULAR_QUEUE;
```
其中MAXSIZE为预设的队列最大长度,TYPE为数据类型。
初始化:
```
void initCircularQueue(CIRCULAR_QUEUE* cq) {
cq->front = 0;
cq->count = 0;
}
```
入队列:
```
int enqueue(CIRCULAR_QUEUE* cq, TYPE x) {
if(cq->count == MAXSIZE) {
return 0;
}
cq->data[(cq->front+cq->count)%MAXSIZE] = x;
cq->count++;
return 1;
}
```
出队列:
```
int dequeue(CIRCULAR_QUEUE* cq, TYPE* x) {
if(cq->count == 0) {
return 0;
}
*x = cq->data[cq->front];
cq->front = (cq->front+1)%MAXSIZE;
cq->count--;
return 1;
}
```
判断队列是否非空:
```
int isCircularQueueEmpty(CIRCULAR_QUEUE cq) {
return cq.count == 0;
}
```
希望能够帮到你。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)