通过LinkedList创建Deque
import java.util.Iterator; import java.util.NoSuchElementException; import java.util.LinkedList; /** from * N o w J a v a . c o m - 时 代 Java **/ public class Deque<Item> implements Iterable<Item> { private int sizeN; private LinkedList<Item> linkedList; // construct an empty deque public Deque() { linkedList = new LinkedList<Item>(); }/*时 代 Java 公 众 号 - nowjava.com 提 供*/ // is the deque empty? public boolean isEmpty() { return linkedList.isEmpty(); } // return the number of items on the deque public int size() { return linkedList.size(); } // insert the item at the front public void addFirst(Item item) { linkedList.addFirst(item); } // insert the item at the end public void addLast(Item item) { linkedList.addLast(item); } // delete and return the item at the front public Item removeFirst() { return linkedList.pollFirst(); } // delete and return the item at the end public Item removeLast() { return linkedList.pollLast(); }