Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 向二叉搜索树添加自定义对象_Java_Generics_Binary Search Tree - Fatal编程技术网

Java 向二叉搜索树添加自定义对象

Java 向二叉搜索树添加自定义对象,java,generics,binary-search-tree,Java,Generics,Binary Search Tree,我对泛型和二进制搜索树还是相当陌生的,我正在尝试向BST添加一个自定义的Student对象,但不知道如何实现它。我的学生班级声明如下: class Student <E>implements Serializable, Comparable { int studentNumber; String firstName; String lastName; String major; double gpa; Student leftChild; Student rightChild;

我对泛型和二进制搜索树还是相当陌生的,我正在尝试向BST添加一个自定义的
Student
对象,但不知道如何实现它。我的
学生
班级声明如下:

class Student <E>implements Serializable, Comparable {

int studentNumber;

String firstName;
String lastName;
String major;
double gpa;

Student leftChild;
Student rightChild;

public Student() {
    this(0, "", "", "", 0.0);
} // end no-argument studentNumberRecordSerializable constructor

public Student(int sNum, String first, String last, String major, double gpa) {
    setstudentNumber(sNum);
    setFirstName(first);
    setLastName(last);
    setMajor(major);
    setGPA(gpa);
} // end four-argument studentNumberRecordSerializable constructor
....
class Student实现了可序列化、可比较的{
国际学生编号;
字符串名;
字符串lastName;
弦乐大调;
双gpa;
学生左撇子;
学生右翼儿童;
公立学生(){
这(0,,,,,0.0);
}//结束无参数studentNumberRecordSerializable构造函数
公立学生(国际学生会,字符串第一,字符串最后,字符串专业,双gpa){
设置学生编号(sNum);
setFirstName(first);
setLastName(last);
塞特梅杰(梅杰);
setGPA(gpa);
}//结束四参数studentNumberRecordSerializable构造函数
....
然后是我的节点类:

class TreeNode<E extends Comparable<E>> {

TreeNode<E> leftNode;
E data;
TreeNode<E> rightNode;

public TreeNode(E nodeData) {
    data = nodeData;
    leftNode = rightNode = null; 
} // end TreeNode constructor

public void insert(E insertValue) {

    if (insertValue.compareTo(data) < 0) {

        if (leftNode == null)
            leftNode = new TreeNode<E>(insertValue);
        else
            leftNode.insert(insertValue);
    } // end if
....
类树节点{
树节点左节点;
E数据;
树节点右节点;
公共树节点(E nodeData){
数据=节点数据;
leftNode=rightNode=null;
}//结束树节点构造函数
公共空白插入(E插入值){
if(insertValue.compareTo(数据)<0){
if(leftNode==null)
leftNode=新树节点(insertValue);
其他的
leftNode.insert(insertValue);
}//如果结束,则结束
....

然后我试图声明
Tree-Tree=new-Tree();
它说那个学生是一个无效的参数。我还想调用
Tree.insertNode(new-student(studentNumber,firstName,lastName,major,gpa))
将其添加到节点。是否有我没有遵循的额外步骤或我没有做对的事情?我对泛型和BST做了很多研究,但我在将两者联系在一起时遇到了问题。请帮助!

修复学生类声明:

class Student implements Serializable, Comparable<Student> {
class Student实现了可序列化、可比较的{

我是否也需要在创建树的类中实现Compariable?