双端队列 Deque 与 随机化队列 RandomizedQueue 的实现
双端队列,也就是栈和队列的结合,同时可以从头和尾进行进出栈 / 队列的功能,看一下他的数据结构就懂了:
1public class Deque<Item> implements Iterable<Item> {
2 public Deque() // construct an empty deque
3 public boolean isEmpty() // is the deque empty?
4 public int size() // return the number of items on the deque
5 public void addFirst(Item item) // add the item to the front
6 public void addLast(Item item) // add the item to the end
7 public Item removeFirst() // remove and return the item from the front
8 public Item removeLast() // remove and return the item from the end
9 public Iterator<Item> iterator() // return an iterator over items in order from front to end
10 public static void main(String[] args) // unit testing (optional)
11}
12
双端队列的实现还是比较简单的(虽然实际上还会是踩了一些微小的坑)。