一.代码部分
1.定义接口:
public interface Queue<E> { void enqueue(E e); E dequeue(); E getFront(); int getSize(); boolean isEmpty(); }
2.基于数组的实现
public class ArrayQueue<E> implements Queue<E> { private ArrayList<E> arrayList; public ArrayQueue(int capacity){ arrayList = new ArrayList<>(capacity); } public ArrayQueue(){ arrayList = new ArrayList<>(); } @Override public void enqueue(E e) { arrayList.addLast(e); } @Override public E dequeue() { return arrayList.removeFirst(); } @Override public E getFront() { return arrayList.get(0); } @Override public int getSize() { return arrayList.getSize(); } @Override public boolean isEmpty() { return arrayList.isEmpty(); } }
原文地址:https://www.cnblogs.com/inspred/p/queue.html
时间: 2024-10-11 10:08:31