如何创建具有有序和预订遍历的二叉树?

时间:2016-11-12 08:32:53

标签: java algorithm binary-tree traversal

我找到了使用有序和预订遍历(http://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/)创建二叉树的实现,除了以下内容我理解了所有内容:

    // What does inStrt being greater than inEnd mean? 
    if (inStrt > inEnd) 
        return null;

    // Why does inStrt == inEnd mean having no children?
    if (inStrt == inEnd)
        return tNode;

    // Why is it that the first call has inIndex - 1 for inEnd, while for the second, inIndex + 1 for inStart? 
    tNode.left = buildTree(in, pre, inStrt, inIndex - 1);
    tNode.right = buildTree(in, pre, inIndex + 1, inEnd);

谢谢你,一定会接受答案

0 个答案:

没有答案