packagecom.eos.wool.test2;import java.util.*;/*** Created by CLP on 2020-06-17.*/
public classPriorityQueueTest {public static List<Integer>insertSort() {
Queue
<Integer> queue = new PriorityQueue<Integer>(12);
List
<Integer> list = new ArrayList<Integer>();
Random random
= newRandom();intaa;for (int i = 0; i < 17; i++) {
aa
=random.nextInt(100);
System.out.println(aa);
queue.add(
newInteger(aa));
}
while(!queue.isEmpty()){
list.add(queue.poll());
}
//左右输出 个数不全;因为poll一次就会删除,所以size会变化,和list一般需要逆序删除一样。//for (int i = 0; i < queue.size(); i++) {//list.add(queue.poll());//} System.out.println(list.toString());returnlist;

}
public static voidmain(String[] args){

System.out.println(Arrays.toString(insertSort().toArray()));
}
}

标签: none

添加新评论