-1
나는 내 코드에 익숙해 져 있기 때문에 코드의 첫 번째 줄만 확인하면된다. 따라서 오류가 발생한 부분이 무엇인지 잘못 이해할 수 없다. 바이너리 검색 트리 null 포인터 예외
public boolean add(E x) {
System.out.println(x);
System.out.println(root);
if(root.equals(null)){
root.equals(x);
return true;
}
if(root.equals(x)){
return false;
}
BinaryNode<E> save = root; //create new nod copy of root
while((!save.left.equals(x)) && (!save.left.equals(null))){ //check so save.nex isnt x and that save.next exists
save=save.left;
}
if(save.left.equals(null)){
save = root; //puts save back to root again
while((!save.right.equals(x)) && (!save.right.equals(null))){
save=save.right;
}
if(save.right.equals(null)){
save.right.equals(x);
return true;
}
} return false;
}
나는 단지 if 문, 내가 존재 나던 뭔가를 ACESS려고하고 있지 않다 있어요 라인
if(root.equals(null)){
에 오류가?
'root.equals (null)'로 무엇을하려합니까? 'if (root == null)'을 사용해 보셨습니까? – AdamMc331