diff --git a/Assignement12/bin/HistogramDataDisplay.class b/Assignement12/bin/HistogramDataDisplay.class index 66578d3..73a9c70 100644 Binary files a/Assignement12/bin/HistogramDataDisplay.class and b/Assignement12/bin/HistogramDataDisplay.class differ diff --git a/Assignement12/src/HistogramDataDisplay.java b/Assignement12/src/HistogramDataDisplay.java index 7bfabff..1e7b8b3 100644 --- a/Assignement12/src/HistogramDataDisplay.java +++ b/Assignement12/src/HistogramDataDisplay.java @@ -1,5 +1,3 @@ -import java.util.Arrays; - public class HistogramDataDisplay extends DataDisplay { public HistogramDataDisplay(String name, Data subject) { @@ -10,14 +8,25 @@ public class HistogramDataDisplay extends DataDisplay { public void update() { System.out.println(getClass() + ": " + name); int[] sortedArray = super.getContent(); - Arrays.sort(sortedArray); + boolean isSorted = false; + while (!isSorted) { + isSorted = true; + for (int i = 0; i < sortedArray.length - 1; i++) { + if (sortedArray[i] > sortedArray[i + 1]) { + int temp = sortedArray[i]; + sortedArray[i] = sortedArray[i + 1]; + sortedArray[i + 1] = temp; + isSorted = false; + } + } + } int lastVal = -1; for (int i : sortedArray) { if (i == lastVal) System.out.print("*"); else { - System.out.format("%s%d\t*",(lastVal==-1)?"":"\n", i); - lastVal=i; + System.out.format("%s%d\t*", (lastVal == -1) ? "" : "\n", i); + lastVal = i; } } System.out.println();