5
這裏我試圖練習製作二叉樹,以便我可以對它們進行不同的操作。JAVA:二叉樹
import java.util.*;
import java.lang.*;
public class Main {
public static void main(String[] args) {
}
}
//Building Binary Trees
class bTree {
static class Node { //remember to initilize a root
String value;
Node left, right;
Node(String value, Node left, Node right) {
this.value = value;
this.left = left;
this.right = right;
}
Node(String value) //THIS IS A SIBLING CONSTRUCTOR
{
this(value, null, null);
}
Node root = new Node("ROOT");
Node lefty = new Node("LEFT0");
Node righty = new Node("RIGHT0");
root.left = lefty;
root.right = righty;
}
Node root = null;
}
爲什麼我得到錯誤:標識符預期在root.left和root.right賦值?
謝謝!
不錯的調試。 +1以獲得更快的答案。 – Juvanis 2012-03-10 17:56:03
所以我不明白。我如何在整個程序中更改節點的左右屬性?編輯:沒關係,我明白了! – 2012-03-10 18:01:30