对于循环队列有几个操作:
1、初始化
2、入队
3、出队
4、遍历队列
5、判队列空,判队列满
具体如何实现,我会在下面通过代码实现
在对循环队列操作之前,先要建立队列结构体元素,
1 typedef struct queue
2 {
3 int * buf;
4 int front;
5 int rear;
6 }queue;
1、初始化
初始化,需要完成的工作是,为新建的队列分配内存空间,然后在将头尾指针置零
1 void initqueue(queue *queue_q)
2 {
3 queue_q->buf = (int *)malloc(sizeof(int)*buf_size);
4 if(queue_q->buf != null) //队列内存分配成功
5 {
6 queue_q->front = queue_q->rear = 0; //初始化头尾指针
7 }
8
9 }
2、入队
入队主要是将数据放到内存中,但是应该放到那一段内存,这就是一个问题了,