#include <stdio.h>
#include <malloc.h>
#define QUEUE_INIT_SIZE 100
#define QUEUE_INC 50
typedef int ElemType;
typedef struct
{
ElemType *data; /* 动态分配存储空间*/
int queuesize;
int front; /*头指针,若队列不空,指向队列头元素*/
int rear; /*尾指针,若队列不空,指向队列尾元素*/
} SqQueue;
bool InitQueue(SqQueue &Q)
{
Q.data = (ElemType *)malloc(QUEUE_INIT_SIZE*sizeof(ElemType));
if(!Q.data )return false;
Q.front = 0; Q.rear = 0; Q.queuesize = QUEUE_INIT_SIZE;
}
bool DestroyQueue(SqQueue &Q)
{
if(Q.data){
free(Q.data);Q.data = NULL;
}
return true;
}
void ClearQueue(SqQueue &Q)
{
Q.front = 0; Q.rear = 0;
}
bool QueueEmpty(SqQueue Q)
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余4页未读,立即下载