this.shiftdown(toBeSwapIdx);
}
}
public boolean isFull(){
return this.maxSize == this.size;
}
public int getMaxSize() {
return maxSize;
}
/**
* @param args
*/
public static void main(String[] args) {
Integer[] data = { 7, 12, 13, 24, 8, 6, 4, 27, 14, 8, 12, 56, 22 };
TopNHeap
while (heap.hasNext()) {
System.out.print(heap.removeTop());
System.out.print(" ");
}
System.out.println(" ");
heap.initHeap(data);
for (int i = 0; i < 10; i++) {
heap.addToHeap(i);
}
while (heap.hasNext()) {
System.out.print(" ");
}
System.out.println(" ");
heap = new TopNHeap
Random rd = new Random();
for (int i = 0; i < 20; i++) {
int value = rd.nextInt(100);
// System.out.print(value);
// System.out.print(" ");
heap.addToHeap(value);
}
System.out.println(" ");
while (heap.hasNext()) {
System.out.print(heap.removeTop());
System.out.print(" ");
}
}
}
测试结果:
Java代码
4 6 7 8 8 12 12 13 14 22 24 27 56
7 8 8 8 9 12 12 13 14 22 24 27 56
60 61 64 65 67 67 71 74 74 97
作者“田麦夜月”