-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingApp.java
More file actions
47 lines (39 loc) · 1.21 KB
/
Copy pathSortingApp.java
File metadata and controls
47 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class SortingApp {
public static String toString(int collection[]) {
String temp = "[";
for (int i = 0; i < collection.length; i++) {
temp += collection[i];
if (i < (collection.length - 1)) {
temp += ", ";
}
}
temp += "]";
return temp;
}
public static void bubbleSort() {
int collection[];
int iterations;
BubbleSort bubble = new BubbleSort();
collection = new int[] { 2, 1, 7, 8, 4 };
iterations = bubble.basicAscending(collection);
collection = new int[] { 2, 1, 7, 8, 4 };
iterations = bubble.basicDescending(collection);
collection = new int[] { 2, 1, 7, 8, 4 };
iterations = bubble.endAfterNoSwapsAscending(collection);
collection = new int[] { 2, 1, 7, 8, 4 };
iterations = bubble.optimisedAscending(collection);
}
public static void insertionSort() {
int collection[];
int iterations;
InsertionSort insert = new InsertionSort();
collection = new int[] { 2, 1, 7, 8, 4 };
iterations = insert.ascending(collection);
collection = new int[] { 2, 1, 7, 8, 4 };
iterations = insert.descending(collection);
}
public static void main(String[] args) {
bubbleSort();
insertionSort();
}
}