1 Star 0 Fork 0

20202321邬昱初/javastudy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CreateBinaryTree.java 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
20202321邬昱初 提交于 3年前 . 20202321
package LBT;
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 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu-yuchu/javastudy.git
git@gitee.com:wu-yuchu/javastudy.git
wu-yuchu
javastudy
javastudy
master

搜索帮助