| title | Algorithm4 Java Solution 1.3.21 | ||
|---|---|---|---|
| date | 2019-07-04 05:47:10 +0800 | ||
| draft | false | ||
| tags |
|
||
| categories |
|
Write a method find() that takes a linked list and a string key as arguments and returns true if some node in the list has key as its item field, false otherwise.
LinkedList implements iterable
private class LinkedListIterator implements Iterator<Item> {
Node cur = first;
@Override
public boolean hasNext() {
return cur != null;
}
@Override
public Item next() {
Item item = cur.item;
cur = cur.next;
return item;
}
}find method:
public static boolean find(_LinkedList<String> l, String key) {
for (String s : l)
if (s.equals(key))
return true;
return false;
}