[20-05-23][Thinking in Java 39]Java Container 11 - PriorityQueue
Posted mirai3usi9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[20-05-23][Thinking in Java 39]Java Container 11 - PriorityQueue相关的知识,希望对你有一定的参考价值。
1 package test_20_2; 2 3 import java.util.PriorityQueue; 4 5 public class PriorityQueueTest { 6 7 public static void main(String[] args) { 8 9 PriorityQueue<Double> priorityQueue = new PriorityQueue<Double>(); 10 11 for (int i = 0; i < 10; i++) { 12 double num = Math.random(); 13 priorityQueue.offer(num); 14 } 15 int len = priorityQueue.size(); 16 17 for (int i = 0; i < len; i++) { 18 System.out.println(priorityQueue.poll()); 19 } 20 } 21 }
结果如下:
0.2770926360588323
0.33959641990390255
0.34947907718022275
0.37961640094552984
0.47218730365522155
0.6396464814107589
0.7152140108374734
0.7284752474925242
0.8653329482114109
0.86765955199973
以上是关于[20-05-23][Thinking in Java 39]Java Container 11 - PriorityQueue的主要内容,如果未能解决你的问题,请参考以下文章
Hacker Rank: Two Strings - thinking in C# 15+ ways
Thinking in Java & Writing in Python