数据结构伪代码的实现(队列篇)
以循环队列为例
#include<stdio.h>
#include<malloc.h>
#include<stdbool.h>
#define MAXSIZE 6
/*
定义数组最大长度
接下来有很多操作都是对MAXSIZE取余
这是一个循环队列
当队列满的时候需要 需要将队尾指向对头
例判断队列是否已满:
if((pQ->rear+1)%MAXSIZE==pQ->front)
*/
typedef struct Queue
{
int *pBase;//新建数组的首地址
int front;
int rear;
}QUEUE;
void init(QUEUE *);
bool en_queue(QUEUE *,int );
bool full_queue(QUEUE*);
void traverse_queue(QUEUE *);
bool out_queue(QUEUE *,int *);
bool empty_queue(QUEUE *);
int main(void)
{
QUEUE Q;
int val;
init(&Q);//创建队列 初始化front和rear
if(empty_queue(&Q))
printf("队列为空!\n");
printf("插入数:\n");
en_queue(&Q,1);
en_queue(&Q,2);
en_queue(&Q,3);
en_queue(&Q,4);
en_queue(&Q,5);
en_queue(&Q,6);
if(empty_queue(&Q))
printf("队列为空!\n");
traverse_queue(&Q);
i