| 3 | import java.util.Comparator; |
| 4 | |
| 5 | public class test { |
| 6 | public static void main(String[] args) { |
| 7 | Student s1 = new Student(1, "张三", 18, "西安"); |
| 8 | Student s2 = new Student(2, "李四", 20, "重庆"); |
| 9 | Student s3 = new Student(3, "王五", 19, "成都"); |
| 10 | Student s4 = new Student(4, "赵六", 22, "深圳"); |
| 11 | Student s5 = new Student(5, "钱七", 21, "北京"); |
| 12 | |
| 13 | MyHeap<Student> myHeap = new MyHeap<>(new Comparator<Student>() { |
| 14 | @Override |
| 15 | public int compare(Student o1, Student o2) { |
| 16 | if(o1.getId() < o2.getId()) { |
| 17 | return -1; |
| 18 | } else if (o1.getId() > o2.getId()) { |
| 19 | return 1; |
| 20 | }else { |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | // return o1.getId() - o2.getId(); |
| 25 | } |
| 26 | }); |
| 27 | myHeap.push(s1); |
| 28 | myHeap.push(s2); |
| 29 | myHeap.push(s3); |
| 30 | myHeap.push(s4); |
| 31 | myHeap.push(s5); |
| 32 | |
| 33 | System.out.println(myHeap.isEmpty()); |
| 34 | System.out.println(myHeap.getHeapSize()); |
| 35 | System.out.println("===================="); |
| 36 | s1.setId(15); |
| 37 | myHeap.resign(s1); |
| 38 | while (!myHeap.isEmpty()) { |
| 39 | System.out.println(myHeap.poll().toString()); |
| 40 | } |
| 41 | |
| 42 | } |
| 43 | } |
nothing calls this directly
no outgoing calls
no test coverage detected