diff --git a/src/sorts/exchange/StableQuickSort.java b/src/sorts/exchange/StableQuickSort.java index 374aa8bd..32d8af80 100644 --- a/src/sorts/exchange/StableQuickSort.java +++ b/src/sorts/exchange/StableQuickSort.java @@ -1,12 +1,11 @@ package sorts.exchange; -import java.util.ArrayList; - import main.ArrayVisualizer; import sorts.templates.Sort; +import utils.ArrayVList; /* - * + * MIT License Copyright (c) 2017 Rodney Shaghoulian @@ -32,9 +31,11 @@ of this software and associated documentation files (the "Software"), to deal */ final public class StableQuickSort extends Sort { + private int length; + public StableQuickSort(ArrayVisualizer arrayVisualizer) { super(arrayVisualizer); - + this.setSortListName("Stable Quick"); this.setRunAllSortsName("Stable Quick Sort"); this.setRunSortName("Stable Quicksort"); @@ -50,42 +51,44 @@ public StableQuickSort(ArrayVisualizer arrayVisualizer) { // Author: Rodney Shaghoulian // Github: github.com/RodneyShag - private void copy(ArrayList list, int [] array, int startIndex) { + private void copy(ArrayVList list, int [] array, int startIndex) { for (int num : list) { Writes.write(array, startIndex++, num, 0.25, false, false); Highlights.markArray(1, startIndex); } } - + /* Partition/Quicksort "Stable Sort" version using O(n) space */ private int stablePartition(int[] array, int start, int end) { int pivotValue = array[start]; //poor pivot choice Highlights.markArray(3, start); - - ArrayList leftList = new ArrayList<>(); - ArrayList rightList = new ArrayList<>(); + + ArrayVList leftList = Writes.createArrayList(this.length); + ArrayVList rightList = Writes.createArrayList(this.length); for (int i = start + 1 ; i <= end; i++) { Highlights.markArray(1, i); - + if (Reads.compareValues(array[i], pivotValue) == -1) { - Writes.mockWrite(end - start, leftList.size(), array[i], 0.25); - Writes.arrayListAdd(leftList, array[i]); - } + // Writes.mockWrite(end - start, leftList.size(), array[i], 0.25); + // Writes.arrayListAdd(leftList, array[i]); + leftList.add(array[i], 0.25, false); + } else { - Writes.mockWrite(end - start, rightList.size(), array[i], 0.25); - Writes.arrayListAdd(rightList, array[i]); + // Writes.mockWrite(end - start, rightList.size(), array[i], 0.25); + // Writes.arrayListAdd(rightList, array[i]); + rightList.add(array[i], 0.25, false); } } /* Recreate array */ this.copy(leftList, array, start); - + int newPivotIndex = start + leftList.size(); - + Writes.write(array, newPivotIndex, pivotValue, 0.25, false, false); Highlights.markArray(1, newPivotIndex); - + this.copy(rightList, array, newPivotIndex + 1); Writes.deleteArrayList(leftList); @@ -101,9 +104,10 @@ private void stableQuickSort(int [] array, int start, int end) { this.stableQuickSort(array, pivotIndex + 1, end); } } - + @Override public void runSort(int[] array, int length, int bucketCount) { + this.length = length; this.stableQuickSort(array, 0, length - 1); } } \ No newline at end of file diff --git a/src/sorts/exchange/StableQuickSortMiddlePivot.java b/src/sorts/exchange/StableQuickSortMiddlePivot.java index 84688372..aafad1d0 100644 --- a/src/sorts/exchange/StableQuickSortMiddlePivot.java +++ b/src/sorts/exchange/StableQuickSortMiddlePivot.java @@ -1,12 +1,11 @@ package sorts.exchange; -import java.util.ArrayList; - import main.ArrayVisualizer; import sorts.templates.Sort; +import utils.ArrayVList; /* - * + * MIT License Copyright (c) 2017 Rodney Shaghoulian @@ -33,9 +32,11 @@ of this software and associated documentation files (the "Software"), to deal */ final public class StableQuickSortMiddlePivot extends Sort { + private int length; + public StableQuickSortMiddlePivot(ArrayVisualizer arrayVisualizer) { super(arrayVisualizer); - + this.setSortListName("Stable Quick (Middle Pivot)"); this.setRunAllSortsName("Stable Quick Sort (Middle Pivot)"); this.setRunSortName("Stable Quicksort (Middle Pivot)"); @@ -54,45 +55,43 @@ public StableQuickSortMiddlePivot(ArrayVisualizer arrayVisualizer) { // Author: Josiah Glosson // Github: github.com/gaming32 - private void copy(ArrayList list, int [] array, int startIndex) { + private void copy(ArrayVList list, int [] array, int startIndex) { for (int num : list) { Writes.write(array, startIndex++, num, 0.25, false, false); Highlights.markArray(1, startIndex); } } - + /* Partition/Quicksort "Stable Sort" version using O(n) space */ private int stablePartition(int[] array, int start, int end) { int pivot = start + (end - start) / 2; int pivotValue = array[pivot]; Highlights.markArray(3, start); Highlights.markArray(4, pivot); - - ArrayList leftList = new ArrayList<>(); - ArrayList rightList = new ArrayList<>(); + + ArrayVList leftList = Writes.createArrayList(this.length); + ArrayVList rightList = Writes.createArrayList(this.length); for (int i = start ; i <= end; i++) { Highlights.markArray(1, i); if (i == pivot) continue; - + if (Reads.compareValues(array[i], pivotValue) == -1) { - Writes.mockWrite(end - start, leftList.size(), array[i], 0.25); - Writes.arrayListAdd(leftList, array[i]); - } + Writes.arrayListAdd(leftList, array[i], true, 0.25); + } else { - Writes.mockWrite(end - start, rightList.size(), array[i], 0.25); - Writes.arrayListAdd(rightList, array[i]); + Writes.arrayListAdd(rightList, array[i], true, 0.25); } } /* Recreate array */ this.copy(leftList, array, start); - + int newPivotIndex = start + leftList.size(); - + Writes.write(array, newPivotIndex, pivotValue, 0.25, false, false); Highlights.markArray(1, newPivotIndex); - + this.copy(rightList, array, newPivotIndex + 1); Writes.deleteArrayList(leftList); @@ -108,9 +107,10 @@ private void stableQuickSort(int [] array, int start, int end) { this.stableQuickSort(array, pivotIndex + 1, end); } } - + @Override public void runSort(int[] array, int length, int bucketCount) { + this.length = length; this.stableQuickSort(array, 0, length - 1); } } \ No newline at end of file diff --git a/src/sorts/hybrid/DropMergeSort.java b/src/sorts/hybrid/DropMergeSort.java index 6cd243f0..69d77051 100644 --- a/src/sorts/hybrid/DropMergeSort.java +++ b/src/sorts/hybrid/DropMergeSort.java @@ -1,14 +1,16 @@ package sorts.hybrid; import sorts.templates.Sort; +import utils.ArrayVList; import main.ArrayVisualizer; import sorts.hybrid.PDQBranchedSort; import java.util.ArrayList; +import java.util.List; /* - * + * MIT License Copyright (c) 2020 fungamer2 and Emil Ernerfeldt Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,7 +34,7 @@ of this software and associated documentation files (the "Software"), to deal final public class DropMergeSort extends Sort { public DropMergeSort(ArrayVisualizer arrayVisualizer) { super(arrayVisualizer); - + this.setSortListName("Drop Merge"); this.setRunAllSortsName("Drop Merge Sort"); this.setRunSortName("Drop Mergesort"); @@ -44,31 +46,30 @@ public DropMergeSort(ArrayVisualizer arrayVisualizer) { this.setUnreasonableLimit(0); this.setBogoSort(false); } - + private final int RECENCY = 8; private final int EARLY_OUT_TEST_AT = 4; private final double EARLY_OUT_DISORDER_FRACTION = 0.6; - - private void truncateArrayList(ArrayList arrayList, int len) { + + private void truncateArrayList(List arrayList, int len) { int size = arrayList.size(); arrayList.subList(len, size).clear(); - Writes.changeAllocAmount(len - size); } - + @Override public void runSort(int[] array, int length, int bucketCount) { if (length < 2) return; - + PDQBranchedSort pdqSort = new PDQBranchedSort(arrayVisualizer); - ArrayList dropped = new ArrayList<>(length); - + List dropped = Writes.createArrayList(length); + int num_dropped_in_a_row = 0; int read = 0; int write = 0; - + int iteration = 0; int early_out_stop = length / EARLY_OUT_TEST_AT; - + while (read < length) { Highlights.markArray(2, read); iteration += 1; @@ -76,15 +77,16 @@ public void runSort(int[] array, int length, int bucketCount) { // We have seen a lot of the elements and dropped a lot of them. // This doesn't look good. Abort. Highlights.clearMark(2); - + for (int i = 0; i < dropped.size(); i++) { Writes.write(array, write++, dropped.get(i), 1, true, false); } Writes.arrayListClear(dropped); pdqSort.customSort(array, 0, length); + Writes.deleteArrayList(dropped); return; } - + if (write == 0 || Reads.compareIndices(array, read, write - 1, 0, false) >= 0) { // The element is order - keep it: Writes.write(array, write++, array[read++], 1, true, false); @@ -136,24 +138,24 @@ public void runSort(int[] array, int length, int bucketCount) { } } } - + Highlights.clearMark(2); - + for (int i = 0; i < dropped.size(); i++) { Writes.write(array, write + i, dropped.get(i), 1, true, false); } - + pdqSort.customSort(array, write, length); - - + + int[] buffer = Writes.createExternalArray(dropped.size()); - + Writes.arraycopy(array, write, buffer, 0, dropped.size(), 1, true, true); - + int i = buffer.length - 1; int j = write - 1; int k = length - 1; - + while (i >= 0) { if (j < 0 || Reads.compareValues(buffer[i], array[j]) == 1) { Writes.write(array, k--, buffer[i--], 1, true, false); @@ -162,7 +164,7 @@ public void runSort(int[] array, int length, int bucketCount) { Writes.write(array, k--, array[j--], 1, true, false); } } - + Writes.deleteArrayList(dropped); Writes.deleteExternalArray(buffer); } diff --git a/src/sorts/select/AnarchySort.java b/src/sorts/select/AnarchySort.java index 4fc5c804..9d3114dc 100644 --- a/src/sorts/select/AnarchySort.java +++ b/src/sorts/select/AnarchySort.java @@ -1,9 +1,8 @@ package sorts.select; -import java.util.ArrayList; - import main.ArrayVisualizer; import sorts.templates.Sort; +import utils.ArrayVList; public final class AnarchySort extends Sort { @@ -22,13 +21,13 @@ public AnarchySort(ArrayVisualizer arrayVisualizer) { } - private boolean containsValue(ArrayList list, int value) { + private boolean containsValue(ArrayVList list, int value) { for (int at = 0; at < list.size(); at++) { this.Delays.sleep(0.001D); this.Highlights.markArray(1, at); this.Writes.startLap(); - boolean comp = (((Integer) list.get(at)).intValue() == value); + boolean comp = list.get(at) == value; this.Writes.stopLap(); if (comp) @@ -59,7 +58,7 @@ private void convert(int[] array, int[] aux, int length) { this.Writes.write(aux, init, array[init], 0.001D, true, true); } - ArrayList t2 = new ArrayList<>(); + ArrayVList t2 = Writes.createArrayList(length); int m = 0; while (m < length) { @@ -71,14 +70,15 @@ private void convert(int[] array, int[] aux, int length) { } i++; } - this.Writes.changeAuxWrites(1); - t2.add(Integer.valueOf(j)); + t2.add(j); this.Highlights.markArray(1, j); this.Delays.sleep(1.0D); this.Writes.write(array, j, m, 1.0D, true, false); m++; } + + Writes.deleteArrayList(t2); } private void sortMainAndAux(int[] array, int[] aux, int length) { diff --git a/src/utils/ArrayVList.java b/src/utils/ArrayVList.java new file mode 100644 index 00000000..e3380093 --- /dev/null +++ b/src/utils/ArrayVList.java @@ -0,0 +1,473 @@ +package utils; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.RandomAccess; +import java.util.Spliterator; +import java.util.function.Consumer; + +import main.ArrayVisualizer; + +public class ArrayVList extends AbstractList implements RandomAccess, Cloneable, java.io.Serializable { + final static int DEFAULT_CAPACITY = 128; + final static double DEFAULT_GROW_FACTOR = 2; + + static ArrayVisualizer arrayVisualizer; + static Reads Reads; + static Writes Writes; + + int[] internal; + double growFactor; + int count, capacity; + + public ArrayVList() { + this(DEFAULT_CAPACITY, DEFAULT_GROW_FACTOR); + } + + public ArrayVList(int capacity) { + this(capacity, DEFAULT_GROW_FACTOR); + } + + public ArrayVList(int capacity, double growFactor) { + if (arrayVisualizer == null) { + arrayVisualizer = ArrayVisualizer.getInstance(); + Reads = arrayVisualizer.getReads(); + Writes = arrayVisualizer.getWrites(); + } + this.internal = new int[capacity]; + arrayVisualizer.getArrays().add(internal); + this.count = 0; + this.capacity = capacity; + this.growFactor = growFactor; + } + + public void delete() { + Writes.changeAllocAmount(-count); + arrayVisualizer.getArrays().remove(internal); + this.internal = null; + this.count = 0; + this.capacity = 0; + } + + @Override + public int size() { + return count; + } + + @Override + public boolean isEmpty() { + return count == 0; + } + + @Override + public boolean contains(Object o) { + return indexOf(o) > -1; + } + + @Override + public Object[] toArray() { + Integer[] result = new Integer[count]; + for (int i = 0; i < count; i++) { + result[i] = internal[i]; + } + return result; + } + + @Override + @SuppressWarnings("unchecked") + public T[] toArray(T[] a) { + if (a.length < count) { + for (int i = 0; i < count; i++) { + a[i] = (T)Integer.valueOf(internal[i]); + } + return a; + } + return (T[])toArray(); + } + + protected void grow() { + int newCapacity = (int)Math.ceil(capacity * growFactor); + int[] newInternal = new int[newCapacity]; + System.arraycopy(internal, 0, newInternal, 0, count); + ArrayList arrays = arrayVisualizer.getArrays(); + arrays.set(arrays.indexOf(internal), newInternal); + this.capacity = newCapacity; + this.internal = newInternal; + } + + public boolean add(int e, double sleep, boolean mark) { + if (count == capacity) { + grow(); + } + Writes.write(internal, count++, e, sleep, mark, true); + Writes.changeAllocAmount(1); + return true; + } + + @Override + public boolean add(Integer e) { + return add(e, 0, false); + } + + private void fastRemove(int index) { + int numMoved = count - index - 1; + if (numMoved > 0) + Writes.arraycopy(internal, index + 1, internal, index, numMoved, 0, false, true); + internal[--count] = 0; + Writes.changeAllocAmount(-1); + } + + @Override + public boolean remove(Object o) { + if (o == null) { + return false; + } else { + for (int i = 0; i < count; i++) { + if (o.equals(internal[i])) { + fastRemove(i); + return true; + } + } + } + return false; + } + + @Override + public boolean containsAll(Collection c) { + return false; + } + + @Override + public boolean addAll(Collection c) { + return false; + } + + @Override + public boolean addAll(int index, Collection c) { + return false; + } + + @Override + public boolean removeAll(Collection c) { + return false; + } + + @Override + public boolean retainAll(Collection c) { + return false; + } + + @Override + public void clear() { + Arrays.fill(internal, 0, count, 0); + Writes.changeAllocAmount(-count); + count = 0; + } + + @Override + public Integer get(int index) { + return internal[index]; + } + + public Integer set(int index, int element, double sleep, boolean mark) { + rangeCheck(index); + int old = internal[index]; + Writes.write(internal, index, element, sleep, mark, true); + return old; + } + + @Override + public Integer set(int index, Integer element) { + return set(index, element, 0, false); + } + + private String outOfBoundsMsg(int index) { + return "Index: " + index + ", Size: " + this.count; + } + + protected void removeRange(int fromIndex, int toIndex) { + int numMoved = count - toIndex; + System.arraycopy(internal, toIndex, internal, fromIndex, + numMoved); + + int sizeOffset = toIndex - fromIndex; + int newSize = count - sizeOffset; + Arrays.fill(internal, newSize, count, 0); + count = newSize; + Writes.changeAllocAmount(-sizeOffset); + } + + private void rangeCheck(int index) { + if (index >= count) + throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); + } + + @Override + public void add(int index, Integer element) { + + } + + @Override + public Integer remove(int index) { + rangeCheck(index); + int old = internal[index]; + fastRemove(index); + return old; + } + + @Override + public int indexOf(Object o) { + if (o == null) { + return -1; + } + if (!(o instanceof Integer)) { + return -1; + } + int value = (Integer)o; + for (int i = 0; i < count; i++) { + if (Reads.compareValues(internal[i], value) == 0) { + return i; + } + } + return -1; + } + + @Override + public int lastIndexOf(Object o) { + if (o == null) { + return -1; + } + if (!(o instanceof Integer)) { + return -1; + } + int value = (Integer)o; + for (int i = count - 1; i >= 0; i--) { + if (Reads.compareValues(internal[i], value) == 0) { + return i; + } + } + return -1; + } + + @Override + public Iterator iterator() { + return new Itr(); + } + + @Override + public ListIterator listIterator() { + return new ListItr(0); + } + + @Override + public ListIterator listIterator(int index) { + return new ListItr(index); + } + + private class Itr implements Iterator { + int cursor; // index of next element to return + int lastRet = -1; // index of last element returned; -1 if no such + + public boolean hasNext() { + return cursor != count; + } + + public Integer next() { + int i = cursor; + if (i >= count) + throw new NoSuchElementException(); + cursor = i + 1; + return ArrayVList.this.internal[lastRet = i]; + } + + public void remove() { + if (lastRet < 0) + throw new IllegalStateException(); + + try { + ArrayVList.this.remove(lastRet); + cursor = lastRet; + lastRet = -1; + } catch (IndexOutOfBoundsException ex) { + throw new ConcurrentModificationException(); + } + } + + @Override + public void forEachRemaining(Consumer consumer) { + Objects.requireNonNull(consumer); + final int size = ArrayVList.this.capacity; + int i = cursor; + if (i >= size) { + return; + } + final int[] internal = ArrayVList.this.internal; + if (i >= internal.length) { + throw new ConcurrentModificationException(); + } + while (i != size) { + consumer.accept(internal[i++]); + } + // update once at end of iteration to reduce heap write traffic + cursor = i; + lastRet = i - 1; + } + } + + private class ListItr extends Itr implements ListIterator { + ListItr(int index) { + super(); + cursor = index; + } + + public boolean hasPrevious() { + return cursor != 0; + } + + public int nextIndex() { + return cursor; + } + + public int previousIndex() { + return cursor - 1; + } + + public Integer previous() { + int i = cursor - 1; + if (i < 0) + throw new NoSuchElementException(); + int[] internal = ArrayVList.this.internal; + if (i >= internal.length) + throw new ConcurrentModificationException(); + cursor = i; + return internal[lastRet = i]; + } + + public void set(Integer e) { + if (lastRet < 0) + throw new IllegalStateException(); + + try { + ArrayVList.this.set(lastRet, e); + } catch (IndexOutOfBoundsException ex) { + throw new ConcurrentModificationException(); + } + } + + public void add(Integer e) { + try { + int i = cursor; + ArrayVList.this.add(i, e); + cursor = i + 1; + lastRet = -1; + } catch (IndexOutOfBoundsException ex) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public List subList(int fromIndex, int toIndex) { + return new SubList(this, 0, fromIndex, toIndex); + } + + private class SubList extends AbstractList implements RandomAccess { + private final ArrayVList parent; + private final int parentOffset; + private final int offset; + int size; + + SubList(ArrayVList parent, + int offset, int fromIndex, int toIndex) { + this.parent = parent; + this.parentOffset = fromIndex; + this.offset = offset + fromIndex; + this.size = toIndex - fromIndex; + } + + public Integer set(int index, int e) { + rangeCheck(index); + int oldValue = ArrayVList.this.internal[offset + index]; + ArrayVList.this.internal[offset + index] = e; + return oldValue; + } + + public Integer get(int index) { + rangeCheck(index); + return ArrayVList.this.internal[offset + index]; + } + + public int size() { + return this.size; + } + + public void add(int index, int e) { + rangeCheckForAdd(index); + parent.add(parentOffset + index, e); + size++; + } + + public Integer remove(int index) { + rangeCheck(index); + int result = parent.remove(parentOffset + index); + this.size--; + return result; + } + + protected void removeRange(int fromIndex, int toIndex) { + parent.removeRange(parentOffset + fromIndex, + parentOffset + toIndex); + this.size -= toIndex - fromIndex; + } + + public Iterator iterator() { + return listIterator(); + } + + public ListIterator listIterator(final int index) { + return null; + } + + public List subList(int fromIndex, int toIndex) { + return null; + // subListRangeCheck(fromIndex, toIndex, size); + // return new SubList(this, offset, fromIndex, toIndex); + } + + private void rangeCheck(int index) { + if (index < 0 || index >= this.size) + throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); + } + + private void rangeCheckForAdd(int index) { + if (index < 0 || index > this.size) + throw new IndexOutOfBoundsException(outOfBoundsMsg(index)); + } + + private String outOfBoundsMsg(int index) { + return "Index: "+index+", Size: "+this.size; + } + + public Spliterator spliterator() { + return null; + } + } + + static void subListRangeCheck(int fromIndex, int toIndex, int size) { + if (fromIndex < 0) + throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); + if (toIndex > size) + throw new IndexOutOfBoundsException("toIndex = " + toIndex); + if (fromIndex > toIndex) + throw new IllegalArgumentException("fromIndex(" + fromIndex + + ") > toIndex(" + toIndex + ")"); + } +} diff --git a/src/utils/Sounds.java b/src/utils/Sounds.java index 5ec58877..cd96dea5 100644 --- a/src/utils/Sounds.java +++ b/src/utils/Sounds.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; import javax.sound.midi.Instrument; import javax.sound.midi.InvalidMidiDataException; @@ -105,7 +107,7 @@ public Sounds(int[] array, ArrayVisualizer arrayVisualizer) { try { MidiSystem.getSequencer(false); this.synth = MidiSystem.getSynthesizer(); - this.synth.open(); + synth.open(); } catch (MidiUnavailableException e) { JErrorPane.invokeCustomErrorMessage("The default MIDI device is unavailable, possibly because it is already being used by another application."); diff --git a/src/utils/Writes.java b/src/utils/Writes.java index 66674984..2056f642 100644 --- a/src/utils/Writes.java +++ b/src/utils/Writes.java @@ -413,6 +413,14 @@ public void reversearraycopy(int[] src, int srcPos, int[] dest, int destPos, int arraycopy(src, srcPos, dest, destPos, length, sleep, mark, aux); } + public ArrayVList createArrayList() { + return new ArrayVList(); + } + + public ArrayVList createArrayList(int defaultCapacity) { + return new ArrayVList(defaultCapacity); + } + public int[] createExternalArray(int length) { this.allocAmount += length; int[] result = new int[length]; @@ -434,12 +442,16 @@ public void deleteExternalArrays(int[]... arrays) { ArrayVisualizer.updateNow(); } - public void arrayListAdd(ArrayList aList, int value) { + public void arrayListAdd(List aList, int value) { allocAmount++; aList.add(value); } - public void arrayListAdd(ArrayList aList, int value, boolean mockWrite, double sleep) { + public void arrayListAdd(List aList, int value, boolean mockWrite, double sleep) { + if (aList instanceof ArrayVList) { + ((ArrayVList)aList).add(value, sleep, false); + return; + } allocAmount++; aList.add(value); if (mockWrite) { @@ -450,22 +462,27 @@ public void arrayListAdd(ArrayList aList, int value, boolean mockWrite, } } - public void arrayListRemoveAt(ArrayList aList, int index) { + public void arrayListRemoveAt(List aList, int index) { allocAmount--; aList.remove(index); } - public void arrayListClear(ArrayList aList) { - allocAmount -= aList.size(); + public void arrayListClear(List aList) { + if (!(aList instanceof ArrayVList)) + allocAmount -= aList.size(); aList.clear(); } - public void deleteArrayList(ArrayList aList) { - allocAmount -= aList.size(); + public void deleteArrayList(List aList) { + if (aList instanceof ArrayVList) { + ((ArrayVList)aList).delete(); + } else { + allocAmount -= aList.size(); + } } - public void deleteExternalArray(ArrayList[] array) { - for (ArrayList aList : array) { + public void deleteExternalArray(List[] array) { + for (List aList : array) { deleteArrayList(aList); } }