qq_45738557 2020-07-14 21:53 采纳率: 0%
浏览 93
已结题

Java测试题,有人可以解答吗



For this question, we define the depth of a tree to be the number of levels in it (so an empty tree has depth 0, a tree with a root and only one leaf to has depth 2, etc.)

A "full" binary tree is one in which all the levels of the tree are full 一 every node in the tree has two children, except for the nodes in the bottom level of the tree, which have none. An “unbalanced" binary tree is one in which some levels are not full, and some paths from the root to a leaf are much shorter than the paths to other leaves.




[10 marks] A “difference tree" is a binary tree in which each node contains an integer, every node in the tree has either two children or no children (a leaf), and every non-leaf node contains a value that is the difference between the value in its left child and the value in its right child.

Here is a partial description of a node in that tree:

public class TreeNode {

public int getValue()

public void setValue(/'nt value)

public TreeNode getLeftChild()

public TreeNode getRightChild()

}

Complete the fixDifcTree(..) method so that it will turn a tree into a valid “difference tree", by changing the values in the non-leaf nodes. Assume that every node has either two children or no children, but the values in the non-leaf nodes may be wrong.

Note, fixDifcTree(..) returns the value in the node in its parameter..

public int fixDifcTree(TreeNode root){

}


  • 写回答

6条回答 默认 最新

  • 浴火_凤凰 2020-07-14 21:54
    关注

    英文看的头晕。。

    评论

报告相同问题?