diff --git a/bin/uebung05/logistics/Demo.class b/bin/uebung05/logistics/Demo.class index 33773c7..fef009c 100644 Binary files a/bin/uebung05/logistics/Demo.class and b/bin/uebung05/logistics/Demo.class differ diff --git a/bin/uebung05/logistics/demo.class b/bin/uebung05/logistics/demo.class deleted file mode 100644 index fef009c..0000000 Binary files a/bin/uebung05/logistics/demo.class and /dev/null differ diff --git a/bin/uebung09/iterator/Array2dIterator.class b/bin/uebung09/iterator/Array2dIterator.class index 1226fc4..53abed5 100644 Binary files a/bin/uebung09/iterator/Array2dIterator.class and b/bin/uebung09/iterator/Array2dIterator.class differ diff --git a/src/uebung09/iterator/Array2dIterator.java b/src/uebung09/iterator/Array2dIterator.java index 7908b24..0310dee 100644 --- a/src/uebung09/iterator/Array2dIterator.java +++ b/src/uebung09/iterator/Array2dIterator.java @@ -2,72 +2,32 @@ package uebung09.iterator; import java.util.ArrayList; import java.util.Iterator; +import java.util.NoSuchElementException; public class Array2dIterator implements Iterator{ private T[][] array; - private ArrayList list; - private int index = 0; + private int row = 0; + private int col = 0; public Array2dIterator(T[][] array) { this.array = array; - list = flatten(); } @Override public boolean hasNext() { - // for (int i = 0; i < array.length; i++) { - // for (int j = 0; j < array[i].length; j++) { - // if (array[i][j+1] != null) { - // return true; - // } - // if (array[i+1][j] != null) { - // return true; - // } - // } - // } - // return false; - - - if (list.get(index)) { - return true; - } else { - return false; + while(row < array.length && (array[row] == null || col >= array[row].length)) { + row++; + col = 0; } - - - // return true; + return row > array.length; } @Override public T next() { - // for (int i = 0; i < array.length; i++) { - // for (int j = 0; j < array[i].length; j++) { - // if (array[i][j+1] != null) { - // return array[i][j+1]; - // } - - // } - // if (array[i+1][0] != null) { - // return array[i+1][0]; - // } - // } - // return null; - - - return list.get(index++); - - } - - private ArrayList flatten(){ - ArrayList list = new ArrayList<>(); - - for (int i = 0; i < array.length; i++) { - for (int j = 0; j < array[i].length; j++) { - list.add(array[i][j]); - } + if (!hasNext()) { + throw new NoSuchElementException(); } - - return list; + return array[row][col++]; } }