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

📄 queuestruct.cpp

📁 创建一棵二叉树
💻 CPP
字号:
//define the functions about SqQueue

#include "stdafx.h"
#include "GlobalDefining.h"
#include "TreeStruct.h"
#include "QueueStruct.h"
#include <iostream.h>
#include <stdlib.h>


//有关SqQueue的基本操作包括:
/*
STATUS InitQueue (SqQueue &Q);
STATUS EnQueue (SqQueue &Q, BiTree e);
STATUS DeQueue (SqQueue &Q, BiTree &e);
*/




STATUS InitQueue (SqQueue &Q)   // 构造一个最大存储空间为MAXQSIZE的空队列Q
{
    if (Q.base == NULL) 
		exit (OVERFLOW);  
    Q.front = Q.rear = 0;
    return OK;
}


STATUS EnQueue (SqQueue &Q, BiTree e)      // 插入元素e为Q的新的队尾元素,并返回OK;  否则返回ERROR
{	  
    if ((Q.rear+1) % MAXQSIZE == Q.front) 
        return ERROR;             //队列满
    Q.rear = (Q.rear+1) % MAXQSIZE;
    Q.base[Q.rear] = e;
    return OK;

}

STATUS DeQueue (SqQueue &Q, BiTree &e)   //删除Q的队头元素,用e返回其值,并返回OK;  否则返回ERROR
{
	if (Q.front == Q.rear) 
		return ERROR;              //队列空
    Q.front = (Q.front+1) % MAXQSIZE;
    e = Q.base[Q.front];
    return OK;
}

⌨️ 快捷键说明

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