Need help starting binary tree?
I need a nudge in the right direction. I have this coded so far >>
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
pu开发者_JS百科blic String toString() {
return String.valueOf(id) + ": " + firstName + " " + lastName;
}
}
I need to create a binary tree that displays the member id with the name. I have looked at endless binary trees but confused how they actually grab this information then proceed with it. Can anyone give me a starting point or some example code that is similar to this?
Read this excellent introduction to binary trees from the Stanford CS Library.
精彩评论