优先级队列
来源:互联网 发布:淘宝网购物女装外套妮子风衣 编辑:程序博客网 时间:2024/05/18 22:16
优先级队列是有排序的
类
public class PriorityQ {private long[] queArray;private int maxSize;private int nItems;public PriorityQ(int s){maxSize=s;queArray=new long[maxSize];nItems=0;}public void insert(long item){int i;if(nItems==0){queArray[nItems++]=item;}else{for(i=nItems-1;i>-1;i--){if(item>queArray[i])queArray[i+1]=queArray[i];else {break;}}queArray[i+1]=item;nItems++;}}public long remove(){return queArray[--nItems];}public long peekMin(){return queArray[nItems-1];}public boolean isEmpty(){return nItems==0;}public boolean isFull(){return nItems==maxSize;}}
主程序
public class PriorityQApp {public static void main(String[] args){PriorityQ thePQ=new PriorityQ(5);thePQ.insert(30);thePQ.insert(50);thePQ.insert(10);thePQ.insert(40);thePQ.insert(20);while(!thePQ.isEmpty()){long item=thePQ.remove();System.out.print(item+" ");}}}
0 0
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- libnids插件
- 天声人語 20150815
- LeetCode Delete Node in a Linked List 刷题 OJ 算法
- ubuntu 14 开启root登陆
- poj 1679__The Unique MST(次小生成树,kruskal)
- 优先级队列
- E-UTRA channel bandwidths per operating band (36.101)
- C# abstract类 和 interface 的 区别
- android中设置控件背景的3种方式
- uva 1447 - Malfatti Circles(几何+二分)
- codeforces 514E E. Darth Vader and Tree(矩阵快速幂 )
- A multiplication game
- 在项目中遇到的 maven 插件常用的配置
- 分布式在线数据库学习 && 资料汇总