栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

15 C++二叉树层次遍历与实现方法 Binary tree hierarchical traversal and implementation method

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

15 C++二叉树层次遍历与实现方法 Binary tree hierarchical traversal and implementation method

#include “function.h”

void Init_stack(SqStack& S) {
S.top = -1;
}

bool Stack_empty(SqStack S) {
if (S.top == -1) {
return true;
}
else {
return false;
}
}

bool Push(SqStack& S, ElemType x) {
if (S.top == 50 - 1) {
return false;
}
S.data[++S.top] = x;
return true;
}

bool GetTop(SqStack S, ElemType& m) {
if (Stack_empty(S)) {
return false;
}
m = S.data[S.top];
return true;
}

bool Pop(SqStack& S, ElemType & x) {
if (Stack_empty(S)) {
return false;
}
x = S.data[S.top–];
return true;
}

void Init_queue(LinkQueue& Q) {
Q.front = Q.rear = (LinkNode*)malloc(sizeof(LinkNode));
Q.front->next = NULL;

}

bool Is_empty(LinkQueue Q) {
if (Q.front == Q.rear) {
return true;
}
else {
return false;
}
}

void EnQueue(LinkQueue& Q, ElemType x) {
LinkNode* s = (LinkNode*)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q.rear->next = s;
Q.rear = s;
}

bool DeQueue(LinkQueue& Q, ElemType & x) {
if (Q.front == Q.rear) return false;
LinkNode* p = Q.front->next;
x = p->data;
Q.front->next = p->next;
if (Q.rear == p) Q.rear = Q.front;
free§;
return true;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1009762.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号