赞
踩
- #include<stdio.h>
- #include<malloc.h>
- #include<stdbool.h>
- #define INITSIZE 20
-
- typedef int ElemType;
- typedef struct SqQueue
- {
- ElemType *base;//队列指针指向分配空间
- int front;
- int rear;
- }SqQueue, *PSqQueue;
-
- void initQueue(PSqQueue Q)
- {
- Q->base = (ElemType*)malloc(INITSIZE * sizeof(ElemType));//分配空间
- Q->rear = Q->front = 0;//初始化为0
- }
-
- void DestroyQueue(PSqQueue Q)//销毁栈
- {
- free(Q->base);//直接释放队列指针
- Q->base = NULL;//重置为NULL
- Q->front = Q->rear = 0;//重置为0
- }
-
- void ClearQueue(PSqQueue Q)//清空队列指针,直接使两个标记重置为0
- {
- Q->front = Q->rear = 0;
- }
-
- void EnQueue(PSqQueue Q, ElemType e)//入队
- {
- if(Q->rear+1 == Q->front)//判断队列是否满,为了区别于队空,队尾下标加1若等于队头标记即为满
- return;
- *(Q->base + Q->rear) = e;//传值
- Q->rear = (Q->rear + 1) % INITSIZE;//队尾下标后移,这里使用取余实现循环下标
- }
-
- void DeQueue(PSqQueue Q, ElemType *e)//出队
- {
- if(Q->fron
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。