繁体   English   中英

如何在二叉搜索树中添加插入对象?

[英]How to add insert an object in binary search tree?

我无法将 studentInfo 对象插入二叉搜索树。

当前代码在“tree.insert(studentInfo)”行给出了一个错误,指出 BST < String > 类型中的方法 insert(String) 不适用于参数 (Student)。


public static void BSTMenu() throws IOException {
        
        GenericBST<String> tree = new GenericBST<>();
        String path = "dataInfo.csv";
        Scanner sc = new Scanner (new FileReader(path));
        String str;
        String [] tokens;
        
        while (sc.hasNext()) {
            str = sc.nextLine();
            tokens = str.split(",");
            String studentID = tokens [0];
            String firstName = tokens [1];
            String lastName = tokens [2];
            String phone = tokens [3];
            String address = tokens [4];
            
        
            Student studentInfo = new Student(studentID, firstName, lastName, phone, address);
            tree.insert(studentInfo);
        
            }       
        ```

编辑树声明,不能在字符串的 GenericBST 中插入 Student 对象。

GenericBST<Student> tree = new GenericBST<>();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM