eclipse-luna
win732bit and jdk1.7
源程序:package ch2.divide;import java.util.Collections;import java.util.Comparator;import java.util.Vector;import ch1.incremental.Greater;/* * 在学习使用之前首先应该注意的是在这个堆的创建初期本身就是一个最大顶堆 * 之后的所有操作都是作为一个最大(小)的顶堆 存在使用的 * */public class PrioQueue { private Vector
测试程序:package ch2.divide;import ch1.incremental.Greater;import ch1.incremental.Less;public class TestQueue { public static void main(String[] args) { Integer a[] = { 5, 1, 9, 4, 6, 2, 0, 3, 8, 7 }, i; String b[] = { 'ChongQing', 'ShangHai', 'AoMen', 'TianJin', 'BeiJing', 'XiangGang' }; Double c[] = { 8.5, 6.3, 1.7, 9.2, 0.5, 2.3, 4.1, 7.4, 5.9, 3.7 }; PrioQueue q = new PrioQueue(); PrioQueue q1 = new PrioQueue(new Less()); PrioQueue q2 = new PrioQueue(new Greater()); for (i = 0; i < 10; i++) { q.enQueue(a[i]); q2.enQueue(c[i]); } for (i = 0; i < 6; i++) q1.enQueue(b[i]); while (!q.empty()) System.out.print(q.deQueue() + ' '); System.out.println(); while (!q1.empty()) System.out.print(q1.deQueue() + ' '); System.out.println(); while (!q2.empty()) System.out.print(q2.deQueue() + ' '); System.out.println(); }}
出错内容以及问题代码
修改内容
输出正确,改错成功
注意在java构造方法中的一个小常识要合理的使用this指针
尽量不要让属性名和参数名重名