linqueue.java
来自「基本的数据结构的java代码」· Java 代码 · 共 49 行
JAVA
49 行
public class LinQueue{
Link front;
Link rear;
int count;
public void LinQueue(){
initiate();
}
public void LinQueue(int sz){
initiate();
}
public void initiate(){
front = rear = null;
count = 0;
}
public void append(Object obj){
Link newNode = new Link(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("队列已空!");
Link 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 isEmpty(){
return count == 0;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?