Files
2019-10-22 18:16:48 +08:00

101 lines
1.8 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*=========================
* 队列的链式存储结构(链队)
==========================*/
#ifndef LINKQUEUE_H
#define LINKQUEUE_H
#include <stdio.h>
#include <stdlib.h> // 提供malloc、realloc、free、exit原型
#include "Status.h" //**▲01 绪论**//
/* 链队元素类型定义 */
typedef int QElemType;
// 队列元素结构
typedef struct QNode {
QElemType data;
struct QNode* next;
} QNode, * QueuePtr;
// 队列结构
typedef struct {
QueuePtr front; // 队头指针
QueuePtr rear; // 队尾指针
} LinkQueue; // 队列的链式存储表示
/*
* 初始化
*
* 构造一个空的链队。
* 初始化成功则返回OK否则返回ERROR。
*
*【注】
* 这里的队列带有头结点
*/
Status InitQueue(LinkQueue* Q);
/*
* 销毁(结构)
*
* 释放链队所占内存。
*/
Status DestroyQueue(LinkQueue* Q);
/*
* 置空(内容)
*
* 这里需要释放链队中非头结点处的空间。
*/
Status ClearQueue(LinkQueue* Q);
/*
* 判空
*
* 判断链队中是否包含有效数据。
*
* 返回值:
* TRUE : 链队为空
* FALSE: 链队不为空
*/
Status QueueEmpty(LinkQueue Q);
/*
* 计数
*
* 返回链队包含的有效元素的数量。
*/
int QueueLength(LinkQueue Q);
/*
* 取值
*
* 获取队头元素将其存储到e中。
* 如果可以找到返回OK否则返回ERROR。
*/
Status GetHead(LinkQueue Q, QElemType* e);
/*
* 入队
*
* 将元素e添加到队列尾部。
*/
Status EnQueue(LinkQueue* Q, QElemType e);
/*
* 出队
*
* 移除队列头部的元素将其存储到e中。
*/
Status DeQueue(LinkQueue* Q, QElemType* e);
/*
* 遍历
*
* 用visit函数访问队列Q
*/
Status QueueTraverse(LinkQueue Q, void(Visit)(QElemType));
#endif