public class LinkQueue<E> {
// 内部类
private class Node {
public Node(E item) {
this.item = item;
}
private Node next;
private E item;
}
private Node top;// 指示删除的节点
private Node bottom;// 指示要增加的节点
// 添加操作
public void add(E target) {
Node newnode = new Node(target);
if (top == null) {
top = newnode;
bottom = newnode;
}
bottom.next = newnode;
bottom = newnode;
}
// 判断是否为空
public boolean isEmpty() {
return top == null;
}
// 出队列操作
public E remove() {
if (top == null) {
return null;
} else {
E temp = top.item;
top = top.next;
return temp;
}
}
}
// 内部类
private class Node {
public Node(E item) {
this.item = item;
}
private Node next;
private E item;
}
private Node top;// 指示删除的节点
private Node bottom;// 指示要增加的节点
// 添加操作
public void add(E target) {
Node newnode = new Node(target);
if (top == null) {
top = newnode;
bottom = newnode;
}
bottom.next = newnode;
bottom = newnode;
}
// 判断是否为空
public boolean isEmpty() {
return top == null;
}
// 出队列操作
public E remove() {
if (top == null) {
return null;
} else {
E temp = top.item;
top = top.next;
return temp;
}
}
}