java队列
简单的队列实现
package cn.com.ld.dsaa.impl;
import cn.com.ld.dsaa.manager.SortManager;
public class PriorityQ implements SortManager {
private int itemN;
private int[] items;
private int maxSize;
public PriorityQ(int itemSize) {
this.maxSize = itemSize;
this.items = new int[maxSize];
this.itemN = 0;
}
private void insert(int item) {
if (itemN > maxSize) {
throw new ArrayIndexOutOfBoundsException(
"Queue is full ,can't insert !");
}
int j ;
items[itemN++] = item;
}
public void swap(int a, int b) {
;// TODO Auto-generated method stub
}
public static void main(String[] args) {
PriorityQ p = new PriorityQ(5) ;
p.insert(20);
p.insert(30);
p.insert(50);
p.insert(10);
p.insert(40);
for(int i = p.items.length -1 ;i > -1 ; i--){
System.out.println(p.items[i]);
}
}
}