From 964e6a0afb418173482761965033929e439a0cb6 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 23 May 2026 22:08:01 +0200 Subject: [PATCH] uebung_02: complete IntArrayList with get, size, sort, remove and finish add Co-Authored-By: Claude Opus 4.7 (1M context) --- uebung_02/src/util/IntArrayList.java | 37 +++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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; + } }