即时通讯卡坚持下面的代码,它应该插入一个键/指针组合到数据结构的节点,并保持它的排序顺序,但顺序似乎是随机的,我只是CANT图出什么错了!爪哇 - 这种排序方法是一个谜
public void add (int val, Node no) {
// Find the index where to insert
int maxval = 0;
for (int o = 0; o < this.values.length; o++)
if (val < this.values[o]) {
maxval = o;
break;
}
// Move all the data from the chosen index one spot forward
for (int o = this.values.length-1; o > maxval; o--) {
this.values[o] = this.values[o-1];
this.children[o] = this.children[o-1];
}
// Insert the value
this.children[maxval] = no;
this.values[maxval] = val;
}
插入一个值会丢弃(覆盖)最大值。这是意图吗? – 2011-05-20 11:52:45
在java中有可用的排序集。你不需要自己实现它。 – 2011-05-20 11:53:32