-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
42 lines (35 loc) · 1.26 KB
/
Main.java
File metadata and controls
42 lines (35 loc) · 1.26 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
import java.util.Random;
public class Main {
// helping method to create an array with random numbers
public static int[] createRandom(int n) {
Random rd = new Random();
int[] array = new int[n];
int min = 0;
int max = 10;
for (int i = 0; i < array.length; i++) {
array[i] = rd.nextInt(max-min+1) + min;
}
return array;
}
public static void printArray(int[] arr) {
System.out.print("[");
for (int i = 0; i <= arr.length - 1; i++) {
System.out.print(arr[i] + " ");
}
System.out.println("]");
}
public static void main(String[] args) {
int[] unsortedArray = createRandom(5);
//int[] unsortedArray = {4,5,2,6,3};
// print out unsorted array
System.out.print("unsorted array: ");
printArray(unsortedArray);
// use a sorting-algorithm to sort the array. low -> high number
//int[] sortedArray = SelectionSort.selectionSort(unsortedArray);
//int[] sortedArray = CountingSort.countingSort(unsortedArray);
int[] sortedArray = QuickSort.initialize(unsortedArray);
// print out sorted array
System.out.print("sorted array: ");
printArray(sortedArray);
}
}