queuefortree.cpp
来自「数据结构中的二叉树的遍历(前序、中序、后序)算法」· C++ 代码 · 共 67 行
CPP
67 行
#include "stdafx.h"
#include <vld.h>
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include "..\\header\\Bitree.h"
Status InitQueue(LinkQueue& Q)
{
Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
if(!Q.front) exit(OVERFLOW);
Q.front->next = NULL;
return OK;
}
Status DestroyQueue(LinkQueue& Q)
{
while(Q.front)
{
Q.rear = Q.front->next;
free(Q.front);
Q.front = Q.rear;
}
return OK;
}
Status EnQueue(LinkQueue& Q, BiTNode* e)
{
if(e==NULL) return ERROR;
QNode* p = (QueuePtr)malloc(sizeof(QNode));
if(!p) exit(OVERFLOW);
p->data = e;
p->next = NULL;
Q.rear->next = p;
Q.rear = p;
return OK;
}
Status DeQueue(LinkQueue& Q, BiTNode* e)
{
if(Q.front == Q.rear) return ERROR;
QNode* p = Q.front->next;
*e = (*p->data);
Q.front->next = p->next;
if(Q.rear == p) Q.rear = Q.front;
free(p);
p = NULL;
return OK;
}
bool IsQueueEmpty(LinkQueue Q)
{
return (Q.front == Q.rear);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?