class Queue{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
public Queue(int s){
maxSize=s;
queArray=new long[maxSize];
front=0;
rear=-1;
nItems=0;
}
public void insert(long j){
if(rear==maxSize-1)//wraparound
rear=-1;
queArray[++rear]=j;
nItems++;
}
public long remove(){//take item from front of queue
long temp=queArray[front++];
if(front==maxSize)
front=0;
nItems--;
return temp;
}
public long peekFront(){
return queArray[front];
}
public boolean isEmpty(){
return (nItems==0);
}
public boolean isFull(){
return (nItems==maxSize);
}
public int size(){
return nItems;
}
}
public class queue {
public static void main(String[] args){
Queue theQueue=new Queue(5);
theQueue.insert(10);
theQueue.insert(20);
theQueue.insert(30);
theQueue.remove();
theQueue.remove();
theQueue.insert(50);
theQueue.insert(60);
while(!theQueue.isEmpty()){
long n=theQueue.remove();
System.out.print(n+" ");
}
System.out.println("");
}
}
public class queue {
public static void main(String[] args){
PriorityQ thePQ=new PriorityQ(5);
thePQ.insert(30);
thePQ.insert(50);
thePQ.insert(10);
while(!thePQ.isEmpty()){
long item=thePQ.remove();
System.out.print(item+" ");
}
System.out.println("");
}
}
class PriorityQ{
//array in sorted order,from max at 0 to min at size-1
private int maxSize;
private long[] queArray;
private int nItems;
public PriorityQ(int s){
maxSize=s;
queArray=new long[maxSize];
nItems=0;
}
public void insert(long item){
int j;
if(nItems==0)
queArray[nItems++]=item;
else{
for(j=nItems-1;j>=0;j--){
if(item>queArray[j])
queArray[j++]=queArray[j];
else
break;
}
}
}
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);
}
}