发布时间:2023-05-07 13:00
二叉树遍历,非递归版
#include #include #include #include #include #include #include #include #include using namespace std; class node { public: char num; node* left; node* right; node() { num = 0; left = NULL; right = NULL; } node(char n) { num = n; left = NULL; right = NULL; } }; void pre(node* head) { if (head != NULL) { stack sta; sta.push(head); while (!sta.empty()) { head = sta.top(); cout << head->num << \" \"; sta.pop(); if (head->right) sta.push(head->right); if (head->left) sta.push(head->left); } } cout << endl; } void mid(node* head) { if (head != NULL) { stack sta; while (!sta.empty()||head) { if (head) { sta.push(head); head = head->left; } else { head = sta.top(); sta.pop(); cout << head->num << \" \"; head = head->right; } } } cout << endl; } void beh(node* head) { if (head != NULL) { stack sta; stack help; sta.push(head); while (!sta.empty()) { head = sta.top(); help.push(sta.top()->num); sta.pop(); if (head->left) sta.push(head->left); if (head->right) sta.push(head->right); } while (!help.empty()) { cout << help.top()<<\" \"; help.pop(); } } cout << endl; } void creatT(node* head) { static char n = \'B\'; if (n == \'F\') return; node* l = new node(); node* r = new node(); l->num = (n ++); r->num = (n ++); head->left = l; head->right = r; creatT(head->left); creatT(head->right); } int main() { node* tree = new node(); tree->num = \'A\'; node* head = tree; creatT(tree); mid(tree); pre(tree); beh(tree); }
fpga的reg怎样初始化_FPGA的复位方法几种方法
我怀疑这是IDEA的BUG,但是我翻遍全网没找到证据!
使用vite构建一个自己的vue3.0的UI组件库,并发布到npm
图的邻接表:广度优先遍历&&深度优先遍历
【Matlab绘图】plot3函数绘制三维点或线图
【Java面试】Spring中 BeanFactory和FactoryBean的区别
摸了俩小时docker-compose的鱼,Dockerfile常用姿势5分钟速成~
搭建企业知识库,知识管理的第一步
NLP07:基于潜在隐语义索引的文本相似度计算
渗透测试提权指南
毛利低于同行/竞争加剧,北交所“车载传感器第一股”首日破发
【多线程】锁策略
记录幻影pin 破解wifi
FPGA学习笔记(FPGA基础知识)
C#使用Objects Comparer进行对象比较
使用ssm框架实现一个简单的注册功能
动作识别阅读笔记(一)《Two-Stream Convolutional Networks for Action Recognition in Videos》
JAVASE——粗略了解JAVA异常
『UE4数字孪生』开发流程浅析2022版(持续更新)
matlab两个三维曲面怎么相交,由散点画出的两个三维曲面,有办法求出交线吗
ItVuer - 免责声明 - 关于我们 - 联系我们
本网站信息来源于互联网,如有侵权请联系:561261067@qq.com
桂ICP备16001015号