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

📄 seqqueue.java

📁 基本的数据结构的java代码
💻 JAVA
字号:
public class SeqQueue implements Queue{
	final int defaultSize = 10;
	int front;
	int rear;
	int count;
	int maxSize;
	Object[] data;
	
	public SeqQueue(){
		this.initiate(defaultSize);
	}
	
	public SeqQueue(int sz){
		this.initiate(sz);
	}
	
	private void initiate(int sz){
		maxSize = sz;
		front = rear = 0;
		count = 0;
		data = new Object[sz];
	}
	
	public void append(Object obj) throws Exception{
		if(count > 0 && front == rear){
			throw new Exception("队列已满!");
		}
		
		data[rear] = obj;
		rear = (rear + 1) % maxSize;
		count ++;
	}
	
	public Object delete() throws Exception{
		if(count == 0){
			throw new Exception("队列已空!");
		}
		
		Object temp = data[front];
		front = (front + 1) % maxSize;
		count --;
		return temp;
	}
	
	public Object getFront() throws Exception{
		if(count == 0){
			throw new Exception("队列已空!");
		}
		
		return data[front];
	}
	
	public boolean notEmpty(){
		return count != 0;
	}
		
}

⌨️ 快捷键说明

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