diff --git a/uebung_02/src/util/IntArrayList.java b/uebung_02/src/util/IntArrayList.java index e705a9d..9f75c7c 100644 --- a/uebung_02/src/util/IntArrayList.java +++ b/uebung_02/src/util/IntArrayList.java @@ -14,7 +14,42 @@ public class IntArrayList { } else { int[] arrTemp = new int[lenght*2]; - + System.arraycopy(arr, 0, arrTemp, 0, lenght); + arr = arrTemp; + lenght = lenght * 2; + arr[lastUnfilledPos] = a; + lastUnfilledPos ++; } } + + public int get(int pos){ + if (pos < 0 || pos >= lastUnfilledPos){ + return -1; + } + return arr[pos]; + } + + public int size(){ + return lastUnfilledPos; + } + + public void sort(){ + int[] view = new int[lastUnfilledPos]; + System.arraycopy(arr, 0, view, 0, lastUnfilledPos); + Sorter sorter = new Sorter(); + sorter.mergeSort(view); + System.arraycopy(view, 0, arr, 0, lastUnfilledPos); + } + + public int remove(int pos){ + if (pos < 0 || pos >= lastUnfilledPos){ + return -1; + } + int removed = arr[pos]; + for (int i = pos; i < lastUnfilledPos -1; i++){ + arr[i] = arr[i+1]; + } + lastUnfilledPos --; + return removed; + } }