Implement Bubble Sort Instead of using Built-in method
This commit is contained in:
parent
760af16e58
commit
6b1af4cf0c
Binary file not shown.
|
@ -1,5 +1,3 @@
|
|||
import java.util.Arrays;
|
||||
|
||||
public class HistogramDataDisplay extends DataDisplay {
|
||||
|
||||
public HistogramDataDisplay(String name, Data subject) {
|
||||
|
@ -10,7 +8,18 @@ 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)
|
||||
|
|
Loading…
Reference in New Issue