⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seqcircularqueue.java

📁 基本数据结构
💻 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];
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -