queuestruct.cpp

来自「创建一棵二叉树」· C++ 代码 · 共 47 行

CPP
47
字号
//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 + =
减小字号Ctrl + -
显示快捷键?