No matter how the initialization, the length of the priority queue is not fixed, you add one, size will be + +, full will be expanded.
Therefore, you must manually maintain the priority queue size, such as the TOPK problem.
When you define a Len,len<max, you add,len++ directly.
After the poll is full, add
Put a bunch of unordered elements into the priority queue, each call to poll, can get the current small top heap, that is, the minimum value inside.
The priority queue is the small top heap by default, and you can pass in the sorting method yourself. It would be nice to spread the opposite order on the big top heap.
//I define the class Public Static classnode{intcap; intPro; PublicNode (intXinty) {Cap=x; Pro=y; }}priorityqueue<Node> Priorityqueue =NewPriorityqueue<> (NewComparator<node>() {@Override Public intCompare (node O1, node O2) {if(o1.pro>O2.pro)return-1; if(o1.pro<O2.pro)return1; return0; } });
Lamda expressions can also be
Without the new Comxxxx class, the direct transfer function can be
The parameter type does not need to fill, will fill you according to the context.
New Priorityqueue<> ((O1,O2),{ if(o1.pro>o2.pro) return -1 ; if (o1.pro<o2.pro) return 1; return 0; });
Java Priority queue some problems