class Ball {
int color;
int disnum, sumnum, addnum;
}class statistic {
Ball[] redBalls = new Ball[32];
Ball[] blueBalls = new Ball[16];
...
}
int color;
int disnum, sumnum, addnum;
}class statistic {
Ball[] redBalls = new Ball[32];
Ball[] blueBalls = new Ball[16];
...
}
import java.util.Iterator;
import java.util.TreeSet;class Ball implements Comparable<Ball> { int id; public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public int compareTo(Ball o) {
// TODO Auto-generated method stub if (this.id > o.id)
return -1;
if (this.id < o.id)
return 1;
return 0;
}}public class TreeSetTest { public static void main(String args[]) {
TreeSet treeSet = new TreeSet();
treeSet.add(12);
treeSet.add(21);
treeSet.add(45);
treeSet.add(8);
System.out.println(treeSet);
// 这样排序是没问题的
TreeSet treeSet1 = new TreeSet();
Ball t = new Ball();
t.setId(41);
Ball t1 = new Ball();
t1.setId(78);
Ball t2 = new Ball();
t2.setId(5);
treeSet1.add(t);
treeSet1.add(t1);
treeSet1.add(t2);
print(treeSet1);
} public static void print(TreeSet treeSet1) {
Iterator it = treeSet1.iterator();
while (it.hasNext()) {
Ball b = (Ball) it.next();
System.out.println(b.getId());
}
}
}