我收到错误消息:BST 不是抽象的,并且不会覆盖 TreeGT 中的抽象方法 height()。我需要一些帮助来理解它的含义,以及如何解决它。
在文件 TreeGT.java 我有以下代码:
public interface TreeGT<E> {
public boolean insert(E item);
public boolean delete(E item);
public boolean find(E item);
public int height();
}
在文件 BST.java 我有以下代码:
import java.util.*;
public class BST<E extends Comparable<E>> implements TreeGT<E> {
private Node root; //Only root by itself
public BST() {
root = null;
}
private static class Node {
Comparable data;
int height; //Height of node
int size; //Number of nodes in tree
private Node left; //Left subtree
private Node right; //Right subtree
Node (Comparable data) { //Constructor for tree
this.data = data;
this.height = 0; //Height zero
this.size = 1; //Root counts
this.left = null; //No left leafs
this.right = null; //No right leafs
}
}
public void makeEmpty() {
root = null;
}
public boolean isEmpty() {
return root == null;
}
public int size() {
if (isEmpty())
throw new Exception("Tree is empty");
return root == null ? 0 : root.size;
}
public boolean insert(E item) {
return false;
}
public boolean delete(E item) {
return false;
}
public boolean find(E item) {
return false;
}
}
PS我只用java编程了几天,所以你必须尽可能简单/直截了当地说话,拜托。另外,我正在尝试创建一个 BST。我认为我走在正确的道路上,不是吗?