【发布时间】:2017-03-31 12:08:59
【问题描述】:
BST(T[] array) {
constructBalancedTree(array, 0, array.length - 1);
}
void constructBalancedTree(T[] array, int i, int j) {
if(i > j) {
return;
}
int mid = (i+j)/2;
Node node = new Node(array[mid]);
constructBalancedTree(array, i, mid-1);
constructBalancedTree(array, mid+1, j);
}
我正在尝试弄清楚如何将其打印出来。我已经创建了:
BST<Integer> t1 = new BST<Integer>(new Integer[] {1, 5, 9, 12, 13, 15})
但是当我尝试打印出来时,它给了我一个参考
【问题讨论】:
-
您没有在代码中的任何地方打印。
-
Whats a Node 这里也没有定义。你想把结果保存在哪里?
-
BST
t1 = new BST (new Integer[] {1, 5, 9, 12, 13, 15}) -
这就是我的主要内容,我无法打印出“System.out.println(t1);”它只是给了我一个参考错误。
-
这是 Object 的默认行为,在你的类中覆盖
toString()。
标签: java