1 Star 0 Fork 0

besti1923/JAVA

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CreateBinaryTree.java 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
yifei 提交于 5年前 . shiyan8
package text.java;
import java.util.LinkedList;
public class CreateBinaryTree {
static BinaryTreeNode root = new BinaryTreeNode();
static int i =0;
static LinkedList<BinaryTreeNode> list = new LinkedList<>();
public static BinaryTreeNode add(char[] ch)//构造二叉树
{
BinaryTreeNode node = null;
if(ch[i]=='#'){
node = null;//'#'为空
i++;
}
else
{
node = new BinaryTreeNode();
node.element = ch[i];
i++;
node.left = add(ch);
node.right = add(ch);
}
return node;
}
static public void level(BinaryTreeNode root){//层序遍历
if(root==null)
{
return;
}
list.add(root);
while (!list.isEmpty())
{
BinaryTreeNode temp = list.poll();
System.out.print(temp.element+" ");
if(temp.left!=null)
list.add(temp.left);
if(temp.right!=null)
list.add(temp.right);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/besti1923/java.git
git@gitee.com:besti1923/java.git
besti1923
java
JAVA
master

搜索帮助