import java.util.TreeSet; public class Graphnode implements Comparable<Graphnode> { private String label; private TreeSet<Graphnode> successors; public Graphnode(String label) { this.label = label; successors = new TreeSet<Graphnode>(); } public void addSuccessor(Graphnode successor) { this.successors.add(successor); } public String getLabel() { return label; } public TreeSet<Graphnode> getSuccessors() { return successors; } public int compareTo(Graphnode o) { return this.label.compareTo(o.getLabel()); } } 为了使得Graphnode可以在TreeSet中顺利插入并比较大小,对Comparable接口重定义