- Notifications
You must be signed in to change notification settings - Fork 363
Expand file tree
/
Copy pathbingo_Sort.java
More file actions
Latest commit
49 lines (40 loc) · 1.32 KB
/
Copy pathbingo_Sort.java
File metadata and controls
49 lines (40 loc) · 1.32 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
importjava.util.Scanner;
publicclassbingo_Sort {
publicstaticvoidbingoSort(int[] arr) {
intmin = arr[0], max = arr[0];
for (inti = 1; i < arr.length; i++) {
if (arr[i] < min)
min = arr[i];
elseif (arr[i] > max)
max = arr[i];
}
int[] flags = newint[max - min + 1];
for (inti = 0; i < arr.length; i++)
flags[arr[i] - min] = 1;
intindex = 0;
for (inti = 0; i < max - min + 1; i++) {
if (flags[i] == 1) {
arr[index] = i + min;
index++;
}
}
}
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
System.out.print("Enter the length of the array: ");
intn = scanner.nextInt();
int[] a = newint[n];
System.out.println("Enter the elements of the array:");
for (inti = 0; i < n; i++)
a[i] = scanner.nextInt();
System.out.println("Original array:");
for (inti = 0; i < n; i++)
System.out.print(a[i] + " ");
System.out.println();
bingoSort(a);
System.out.println("Sorted array:");
for (inti = 0; i < n; i++)
System.out.print(a[i] + " ");
System.out.println();
}
}