1. 问题描述
用递归算法绘制一棵树
2. 解决思路
用二叉树的数据结构来描述树的结构,首先创建一个二叉树,创建时要初始化节点的一些信息,伪代码如下:
If current depth is last
then return null
End If
Create a branch
If current branch is left
then initial the branch as a left branch
Else
then initial the branch as a right branch
End If
Create the left branch of this recursively
Create the right branch of this recursively
return the root branch
then return null
End If
Create a branch
If current branch is left
then initial the branch as a left branch
Else
then initial the branch as a right branch
End If
Create the left branch of this recursively
Create the right branch of this recursively
return the root branch
然后再遍历二叉树,遍历的同时绘制树枝,伪代码如下: