需要帮助启动二叉树?

时间:2011-06-18 16:36:28

标签: java binary-tree

我需要朝着正确的方向努力。到目前为止我有这个编码>>

import java.util.Scanner;

class clubmember {

    public static void main(String[] args) {

        int id;
        String fname, lname;
        Scanner input = new Scanner(System.in);

        System.out.println("ID>");
        id = input.nextInt();

        System.out.println("Fname >");
        fname = input.next();

        System.out.println("lname >");
        lname = input.next();


        Person object1 = new Person(id, fname, lname);

        System.out.println(object1);


    }
}




public class Person {
    private final int id;
    private final String firstName;
    private final String lastName;


    public Person(int id, String firstName, String lastName) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public int getId() {
        return id;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    @Override
    public String toString() {
        return String.valueOf(id) + ": " + firstName + " " + lastName;
    }
}

我需要创建一个显示名称成员ID的二叉树。我已经看过无穷无尽的二叉树,但却混淆了他们如何抓住这些信息然后继续它。任何人都可以给我一个起点或一些与此相似的示例代码吗?

1 个答案:

答案 0 :(得分:1)

阅读斯坦福大学图书馆的优秀introduction to binary trees