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

📄 linqueue.java

📁 基本的数据结构的java代码
💻 JAVA
字号:
public class LinQueue implements Queue{
	Node front;
	Node rear;
	int count;
	
	public LinQueue(){
		initiate();
	}
	
	public LinQueue(int sz){
		initiate();
	}
	
	private void initiate(){
		front = rear = null;
		count = 0;
	}
	
	public void append(Object obj){
		Node newNode = new Node(obj,null);
		
		if(rear != null)
			rear.next = newNode;
		rear = newNode;
		if(front == null)
			front = newNode;
		count ++;
	}
	
	public Object delete() throws Exception{
		if(count == 0)
			throw new Exception("队列已空!");
		
		Node temp = front;
		front = front.next; 
		count --;
		return temp.getElement();
	}
	
	public Object getFront() throws Exception{
		if(count == 0)
			throw new Exception("队列已空!");
		return front.getElement();
	}
	
	public boolean notEmpty(){
		return count != 0;
	}
}

⌨️ 快捷键说明

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