forked from techpanja/interviewproblems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSorting.java
More file actions
49 lines (40 loc) · 1.6 KB
/
TestSorting.java
File metadata and controls
49 lines (40 loc) · 1.6 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
48
49
package sorting.test;
import sorting.algorithms.BubbleSort;
import sorting.algorithms.InsertionSort;
import sorting.algorithms.QuickSort;
import sorting.algorithms.SelectionSort;
/**
* Sorting Algorithm Properties:
* adaptive (performance adapts to the initial order of elements);
* stable (insertion sort retains relative order of the same elements);
* in-place (requires constant amount of additional space);
* online (new elements can be added during the sort).
*
* Main class to execute all algorithms.
* User: rpanjrath
* Date: 8/20/13
* Time: 2:56 PM
*/
public class TestSorting {
public static void main(String[] args) {
TestSorting testSorting = new TestSorting();
int[] inputArray = {6, 3, 4, 5, 10, 8, 99, 0};
BubbleSort bubbleSort = new BubbleSort();
int[] bubbleSortedArray = bubbleSort.sort(inputArray);
// testSorting.printResults(bubbleSortedArray);
SelectionSort selectionSort = new SelectionSort();
int[] selectionSortedArray = selectionSort.sort(inputArray);
// testSorting.printResults(selectionSortedArray);
InsertionSort insertionSort = new InsertionSort();
int[] insertionSortedArray = insertionSort.sort(inputArray);
// testSorting.printResults(insertionSortedArray);
QuickSort quickSort = new QuickSort();
int[] quickSortedArray = quickSort.sort(inputArray);
// testSorting.printResults(quickSortedArray);
}
private void printResults(int[] sortedArray) {
for (int i = 0; i < sortedArray.length; i++) {
System.out.println(sortedArray[i]);
}
}
}