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
查看全文
相关阅读:
AOP-面向切面编程-1
记一次付工解决Sqlserver问题的过程
Mysql ---Sqlserver数据迁移到Mysql(Mysql建表迁移数据)
Mysql ---部署,创建用户
【C++】C++未定义行为
【C++】回看面向对象与C++
【作业】2017级面向对象程序设计——总结作业
【笔记】Cocos2dx学习笔记
【个人】绝地求生—吃豆人
【团队】汇总博客
原文地址:https://www.cnblogs.com/junnyfeng/p/192929.html
最新文章
前缀、中缀、后缀表达式
C++常用STL
Introduction to TCP/IP
个人疑惑
Internet History,Technology and Security
bzoj3669 [Noi2014]魔法森林
bzoj2631 tree
bzoj2002 [Hnoi2010]Bounce 弹飞绵羊
bzoj2049 [Sdoi2008]Cave 洞穴勘测 link cut tree入门
bzoj1827 [Usaco2010 Mar]gather 奶牛大集会
热门文章
bzoj2754 [SCOI2012]喵星球上的点名
bzoj3172 [Tjoi2013]单词
bzoj2938 [Poi2000]病毒
bzoj2815 ZJOI2012 灾难
bzoj1030 [JSOI2007]文本生成器
问题 引用对象赋值问题(替换集合中某一元素)
WPF binding
WPF 新突破
Excel-根据分隔符将一个单元格的内容分发到多个单元格
NPOI
Copyright © 2011-2022 走看看