⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqqueue.c

📁 队列(Queue)是限定只能在表的一端进行插入和在另一端进行删除操作的线性表。在表中
💻 C
字号:
/*
 * 作者:antigloss
 * 最后修改:05-9-7 19:30
 * 蚂蚁的 C/C++ 标准编程
 *    cpp.ga-la.com
 */

#include <stdio.h>
#include <stdlib.h>
#include "../header/sqqueue.h"

/* begin of DeQueue 05-9-7 19:10 */
int DeQueue(SqQueue *Q) /* 出队 */
{
	if ( Q->front == Q->rear ) {
		return 0; /* 队空 */
	}
	Q->front = ++Q->front % MAXSIZE;
	return 1;
} /* end of DeQueue */

/* begin of Destroy 05-9-7 19:20 */
void Destroy(SqQueue *Q) /* 销毁队列 */
{
	free(Q->base);
	Q->base = NULL;
	Q->front = Q->rear = 0;
} /* end of Destroy */

/* begin of EnQueue 05-9-7 19:05 */
int EnQueue(SqQueue *Q, ElemType e) /* 入队 */
{
	if ( (Q->rear + 1) % MAXSIZE == Q->front ) {
		return 0; /* 队满(此判断队满法的代价是,少利用一个空间) */
	}
	Q->base[Q->rear] = e;
	Q->rear = ++Q->rear % MAXSIZE;
	return 1;
} /* end of EnQueue */

/* begin of InitQueue 05-9-7 19:00 */
int InitQueue(SqQueue *Q) /* 建立空队列 */
{
	Q->base = malloc( MAXSIZE * sizeof *Q->base );
	if (!Q->base) {
		return 0;
	}
	Q->front = Q->rear = 0;
	return 1;
} /* end of InitQueue */

/* begin of Length 05-9-7 17:15 */
unsigned Length(SqQueue *Q) /* 队列长度 */
{
	return (Q->rear - Q->front + MAXSIZE) % MAXSIZE;
} /* end of Length */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -