📄 fila.java
字号:
package util;
public class Fila {
public Node top;
private Node tail;
public int length;
public Fila() {
length = 0;
top = null;
tail = null;
}
public void enfileirar(Object object) {
Node n = new Node(object, null);
if (top != null) {
Node t = tail;
t.next = n;
tail = n;
} else top = tail = n;
length++;
}
/**
* @return null if queue is Empty;
*/
public Object desenfileirar() {
if (length == 0) return null;
else if (length == 1) {
Node t = top;
top = tail = null;
length--;
return t.object;
} else {
Node t = top;
top = t.next;
length--;
return t.object;
}
}
}
class Node {
public Object object;
public Node next;
public Node(Object object, Node next) {
this.object = object;
this.next = next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -