Java二叉树创建

   /*
     * 先序创建二叉树
     * 返回:根节点
     */
    public TreeNode<T>  creatBinaryPre(LinkedList<T> treeData)
    {
        TreeNode<T> root=null;
        T data=treeData.removeFirst();
        if (data!=null) 
        {
            root=new TreeNode<T>(data, null, null);
            root.left=creatBinaryPre(treeData);
            root.right=creatBinaryPre(treeData);
        }
        return root;
    }

猜你喜欢

转载自blog.csdn.net/qq_39559604/article/details/80207641
今日推荐