?? seqcircularqueue.java
字號:
package circularQueue;
public class SeqCircularQueue implements Queue
{
private int front=0,rear=0;
private Object[] queue;
public SeqCircularQueue(int maxSize){queue=new Object[maxSize];}
public void insert(Object o)
{
int temp=rear;
rear=(rear+1)%queue.length;
if (front==rear)
{
rear=temp;
throw new FullQueueException();
}
queue[rear]=o;
}
public Object remove()
{
if (front==rear)throw new EmptyQueueException();
front=(front+1)%queue.length;
return queue[front];
}
public class EmptyQueueException extends RuntimeException{
/**
*
*/
private static final long serialVersionUID = -4648041708571387891L;}
public class FullQueueException extends RuntimeException{
/**
*
*/
private static final long serialVersionUID = -5227957713299836660L;}
public boolean isEmpty(){return front==rear;}
public boolean isFull(){return ((rear+1)%queue.length)==front;}
public Object getFront()
{
if (front==rear)throw new FullQueueException();
return queue[front];
}
public Object getRear()
{
if (front==rear)throw new EmptyQueueException();
return queue[rear];
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -