0
AVLNode 및 AVLTree 클래스가 있고 노드를 제거하고 삽입하는 메서드가 있고 인쇄 메서드가 있습니다. 이러한 메서드를 사용하여 AVL 트리를 만들고 싶습니다. 입력에 나는 "x를 추가하십시오"와 "x를 제거하십시오"쓰고 싶다. 내가 쓴하지만 난 아무것도 인쇄하지 않을 때Java에서 AVL 트리 사용
public static void main(String[] args) throws IOException {
int i;
BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(scanner.readLine());
String[] words = new String[n];
AVLTree<Integer> t = new AVLTree<Integer>();
for (i = 0; i < n; i++) {
String splitn = scanner.readLine();
words[i] = (splitn.split(" ")[0]);
int M = Integer.parseInt(splitn.split(" ")[1]);
if (words[i] == "Add") {
t.insert(M);
}
if (words[i] == "Remove") {
t.remove(M);
}
}
t.print();
}
아, 감사합니다! – 10001a
' "덧셈".equals (words [i])'가 더 좋습니다 ('NullPointerException'의 위험이 없습니다) –