我的代碼下面我定義了一個嵌套類時出了什麼問題? 它抱怨說:CNode不能解析爲一個類型Java:無法解析到一個類型
package compute;
public class CBTree {
public CNode root;
public void addNode(int key){
CNode newNode = new CNode(key);
// now to find an appropriate place for this new node
// 1 it could be placed at root
if (null == root){ // to void c-style mistakes a==null (with a=null) is not prefered
root = newNode;
}
// if not then find the best spot (which will be once of the
CNode currentRoot = root;
while(true){
if (key < currentRoot.key){
if (null == currentRoot.left){
currentRoot.left = newNode;
break;
} else{
currentRoot = currentRoot.left;
} else{//if (key < currentRoot.key)
if (null == currentRoot.right){
currentRoot.right = newNode;
break;
}else{
currentRoot = currentRoot.right;
}
}
}//while
class CNode{
int key;
public CNode left;
public CNode right;
/**
* Constructor
*/
public CNode(int key){
this.key = key;
}
/**
* Display the node
*/
public void display(){
System.out.println("node:"+ key);
}
}
}
opps!我沒有注意到它,因爲我用記事本並將代碼粘貼到eclipse上 –