linqueue.java

来自「数据结构(java描述)课件(第四讲:图论)」· Java 代码 · 共 49 行

JAVA
49
字号
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 + =
减小字号Ctrl + -
显示快捷键?