

代码:
package com.weyan;
import com.weyan.list.CircleLinkedList;
import com.weyan.list.List;
public class Queue<E> {
private List<E> list = new CircleLinkedList<>();
//元素个数
public int size() {
return list.size();
}
//队列是否为空
public boolean isEmpty() {
return list.isEmpty();
}
//入队
public void enQueue(E element) {
list.add(element);
}
//出队
public E deQueue() {
return list.remove(0);
}
//队头元素
public E front() {
return list.get(0);
}
}
验证结果:

网友评论