私は自分自身を実装したキュークラスからキューオブジェクトを覗いているプログラムの一部をデバッグしようとしていますので、それを繰り返してすべての要素を出力してキューを変更せずに何が問題になっているかを確認しようとしています。これどうやってするの?キューを反復処理する方法私は自分自身を実装しましたか?
マイキュークラス(QueueLinkedListが名前です):
public class QueueLinkedList<Customer> implements Queue<Customer> {
Node first, last;
public class Node {
Customer ele;
Node next;
}
public QueueLinkedList() {}
public boolean isEmpty() {
return first == null;
}
public QueueLinkedList<Customer> enqueue(Customer ele) {
Node current = last;
last = new Node();
last.ele = ele;
last.next = null;
if (current == null)
first = last;
else
current.next = last;
return this;
}
public Customer dequeue() {
if (isEmpty())
throw new java.util.NoSuchElementException();
Customer ele = first.ele;
first = first.next;
return ele;
}
public Customer peek() {
Customer ele = first.ele;
return ele;
}
:あなたは
QueueLinkedList
は常にCustomer
オブジェクトのキューになりたい場合はあるいは、あなたはにクラス宣言を変更する必要があります。 'QueueLinkedList()'コンストラクタは 'QueueLinkedList'クラスになければなりません。そこでは、うまくコンパイルできません。 – davidxxx
これはQueueLinkedListクラスです –
'Iterable'インターフェースを実装し、そのための' Iterator'を作成する必要があります。 –