下面我定义了一个嵌套类的代码有什么问题?它抱怨说:CNode 无法解析为一个类型
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);
}
}
}