-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathQuickSort.java
More file actions
45 lines (36 loc) · 1.16 KB
/
QuickSort.java
File metadata and controls
45 lines (36 loc) · 1.16 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
package sortingAlgorithms;
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;
public class QuickSort {
int count = 0;
public static int getRandomValue(int Min, int Max) {
// Get and return the random integer within Min and Max
return ThreadLocalRandom.current().nextInt(Min, Max + 1);
}
// A utility function to swap two elements
static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
// A utility function to print arrays.array of size n
static void printArray(int[] arr) {
int n = arr.length;
for (int i = 0; i < n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}
public static void main(String[] args) {
int Min = 1, Max = 100;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = getRandomValue(Min, Max);
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("Given Array");
printArray(arr);
}
}