普林斯顿算法week2的deque实现 check iterator() 这个test搞了我一整天 没解决 想问问大家问题出在哪里?
题目是这样的:
Dequeue. A double-ended queue or deque (pronounced "deck") is a generalization of a stack and a queue that supports adding and removing items from either the front or the back of the data structure. Create a generic data type Deque that implements the following API: public class Deque<Item> implements Iterable<Item> { public Deque() // construct an empty deque public boolean isEmpty() // is the deque empty? public int size() // return the number of items on the deque public void addFirst(Item item) // add the item to the front public void addLast(Item item) // add the item to the end public Item removeFirst() // remove and return the item from the front public Item removeLast() // remove and return the item from the end public Iterator<Item> iterator() // return an iterator over items in order from front to end public static void main(String[] args) // unit testing}我打算用双链表做,coursera上其他函数检测都正常,唯独Iterator函数通不过 我的代码是这样的:我觉得问题是出在Iterator几个重写的函数上了。但是我看了一个通过的代码,和我的几乎是一模一样的。我百思不得其解,有会的同学请给我一些指教。
|