zoukankan
html css js c++ java
打印树
利用了树的中序遍历,不过是从右边到左边的中序遍历。
#include
<
iostream.h
>
#include
"
tree.h
"
template
<
class
NODETYPE
>
void
outputTree(TreeNode
<
NODETYPE
>
*
ptr,
int
totalSpaces)
{
if
(ptr
!=
0
)
{
outputTree(ptr
->
rightPtr,totalSpaces
+
5
);
for
(
int
i
=
0
;i
<
totalSpaces;i
++
)
cout
<<
'
'
;
cout
<<
ptr
->
getData()
<<
endl;
outputTree(ptr
->
leftPtr,totalSpaces
+
5
);
}
}
int
main()
{
Tree
<
int
>
intTree;
int
intVal;
cout
<<
"
Enter 15 integer valuse\n
"
;
for
(
int
i
=
0
;i
<
15
;i
++
)
{
cin
>>
intVal;
intTree.insertNode(intVal);
}
outputTree(intTree.rootPtr,
0
);
return
0
;
}
运行结果:
99
97
92
83
72
71
69
49
44
40
32
28
19
18
11
查看全文
相关阅读:
第06组 Alpha冲刺(6/6)
第06组 Alpha冲刺(5/6)
第06组 Alpha冲刺(4/6)
第06组 Alpha冲刺(3/6)
第06组 Alpha冲刺(2/6)
第06组 Alpha冲刺(1/6)
第06组 团队Git现场编程实战
团队项目-需求分析报告
团队项目-选题报告
第二次结对编程作业
原文地址:https://www.cnblogs.com/junnyfeng/p/192929.html
最新文章
Redis 获取和设置密码
c# DataRow[]转Datatable
Vue3.0结合bootstrap做多页面应用(2)基础配置
Vue3.0结合bootstrap做多页面应用(1)创建项目
C#项目 App.config 配置文件不同使用环境配置
视频推流模式HLS,HTTP,RTSP,RTMP协议的区别
websocket-shap 函数Broadcast的使用方法
端口号介绍及使用
C# Dictionary 函数解析及使用方法
自托管websocket和webapi部署云服务器域名及远程访问
热门文章
第06组 Alpha冲刺(4/6)
第06组 Alpha冲刺(3/6)
第06组 Alpha冲刺(2/6)
第06组 Alpha冲刺(1/6)
第06组 团队Git现场编程实战
第06组 团队项目-需求分析报告
团队项目-选题报告
第二次结对编程作业
第6组 团队展示
第一次结对编程作业
Copyright © 2011-2022 走看看