-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingSolution.java
More file actions
37 lines (33 loc) · 1.07 KB
/
SortingSolution.java
File metadata and controls
37 lines (33 loc) · 1.07 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
import java.util.*;
class SortingSolution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
for (int i = 0; i < 5; i++) {
arr[i] = sc.nextInt();
}
System.out.print("Array : ");
for (int i = 0; i < 5; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
int[] arr2 = Arrays.copyOf(arr, arr.length);
int[] arr3 = Arrays.copyOf(arr, arr.length);
int[] arr4 = Arrays.copyOf(arr, arr.length);
System.out.print("using bubble sort : ");
for (int i = arr.length - 1; i >= 0; i--) {
for (int j = 0; j < i; j++) {
if (arr2[i] < arr2[j]) {
int temp = arr2[i];
arr2[i] = arr2[j];
arr2[j] = temp;
}
}
}
for (int i = 0; i < 5; i++) {
System.out.print(arr2[i] + " ");
}
System.out.println();
System.out.print("using quicksort : ");
}
}