Chapter4:优先级队列(原理)
来源:互联网 发布:sql文件怎么导入数据库 编辑:程序博客网 时间:2024/05/16 15:00
package chapter4;
public class PriorityQ {
/**
* @优先级队列
*/
public static void main(String[] args) {
PriorityX thePri = new PriorityX(5);
thePri.insert(30);
thePri.insert(50);
thePri.insert(10);
thePri.insert(40);
thePri.insert(20);
while(!thePri.isEmpty()){
int temp = thePri.remove();
System.out.println(temp);
}
}
}
class PriorityX{
private int maxSize;
private int[] queArray;
private int nItems;
public PriorityX(int max){
maxSize = max;
queArray = new int[maxSize];
nItems = 0;
}
public void insert(int value){
int j;
if(nItems==0)
queArray[0] = value;
else{
for(j=nItems-1;j>=0;j--){
if(queArray[j]<value){
queArray[j+1] = queArray[j];
}else
break;
}
queArray[j+1] = value;
}
nItems++;
}
public int remove(){
return queArray[--nItems];
}
public int peekMin(){
return queArray[nItems-1];
}
public boolean isEmpty(){
return (nItems==0);
}
public boolean isFull(){
return (nItems==maxSize);
}
}
- Chapter4:优先级队列(原理)
- Chapter4:普通队列(原理)
- Chapter4:堆栈(原理)
- chapter4 运算符及其优先级
- java之中PriorityQueue实现原理(具有优先级的队列)
- 优先级队列 (小根堆)
- HDOJ1896Stones(队列优先级)
- 堆(优先级队列)
- (十二)优先级队列
- 并发队列-无界阻塞优先级队列PriorityBlockingQueue原理探究
- hdu1871无题(优先级队列)
- 优先级队列(哈夫曼树)poj3253
- 优先级队列 ural1306(poj2623)
- 优先级队列(大顶堆实现)
- 【数据结构】优先级队列(一)
- 【数据结构】优先级队列(二)
- C++ 优先级队列(priority_queue)
- [数据结构]Priority_queue(优先级队列)
- AlertDialog和AlertDialog.Builder?两者区别
- Tomcat7.0.27下安装Solr4.6.0 (转)
- lua中的迭代器
- Solr开发步骤
- 颜色特征提取(一)------颜色直方图
- Chapter4:优先级队列(原理)
- RecyclerView的使用
- java常用快捷键
- Bundle类用于传递值
- fs通过lua注册mysql分机
- e.Handled的意思
- OC利用正则表达式获取网络资源(网络爬虫)
- Android实战技巧之二十九:画布Canvas
- JFinal学习笔记一