Commit 9bf29606 authored by Anya Helene Bagge's avatar Anya Helene Bagge 🦆

Etter forelesning

parent 9881191b
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import inf101.v16.datastructures.IList;
import inf101.v16.datastructures.MyList;
import inf101.v16.datastructures.Range;
public class Main {
public static void main(String[] args) {
String[] a = {"Hei,", "på", "deg", "!"};
List<String> list = new ArrayList<>();
list.add("Hei");
list.add("på");
list.add("deg!");
Iterator<String> iterator = list.iterator();
while(iterator.hasNext())
System.out.println(iterator.next());
for(int i : new Range(0, 10)) {
System.out.println(i);
}
}
}
......@@ -3,6 +3,21 @@ package inf101.v16.datastructures;
import java.util.Iterator;
public class Range implements Iterable<Integer>, IRange{
private final class RangeIterator implements Iterator<Integer> {
int teller = low;
@Override
public boolean hasNext() {
return teller < high;
}
@Override
public Integer next() {
return teller++;
}
}
private int low;
private int high;
......@@ -14,22 +29,6 @@ public class Range implements Iterable<Integer>, IRange{
this.high = high;
}
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
@Override
public boolean hasNext() {
return false; // TODO
}
@Override
public Integer next() {
return 0; // TODO
}
};
}
@Override
public int getLow() {
......@@ -40,6 +39,12 @@ public class Range implements Iterable<Integer>, IRange{
public int getHigh() {
return high;
}
@Override
public Iterator<Integer> iterator() {
return new RangeIterator();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment