リンク リスト クラスを作成しており、このcontains()
メソッドを実装しようとしています。
私はhead
とtail
センチネル ノードを持っているので、 でループを開始しhead.next
ます。length
リストのサイズです。私があなたたちに与えることができるすべての試合:O
public boolean contains(T entry) {
boolean found = false;
Node current = head.next;
for (int i = 0; i < length; i++) {
if (current.equals(entry)) {
found = true;
}
current = current.next;
}
return found;
}