12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import java.util.Iterator;
-
- abstract class EnkelReseptListe implements Iterable<Resept> {
- protected class Node {
- Node next;
- Resept val;
-
- Node(Resept val) {
- this.val = val;
- }
- }
-
- Node first;
- Node last;
-
- abstract public void settInn(Resept val);
-
- public Resept finn(int id) {
- Node n = first;
-
- while (n != null) {
- if (n.val.id == id)
- return n.val;
-
- n = n.next;
- }
-
- return null;
- }
-
- public Iterator<Resept> iterator() {
- return new Iterator<Resept>() {
- private Node n = first;
-
- public boolean hasNext() {
- return n != null;
- }
-
- public Resept next() {
- Resept r = n.val;
- n = n.next;
- return r;
- }
- };
- }
- }
|