- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyedIndexSort.java
More file actions
Latest commit
28 lines (23 loc) · 792 Bytes
/
Copy pathKeyedIndexSort.java
File metadata and controls
28 lines (23 loc) · 792 Bytes
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
packagestring;
publicclassKeyedIndexSort {
publicstaticvoidmain(String[] args) {
char[] a = {'a', 'b', 'c', 'd', 'e', 'a', 'b', 'a', 'b', 'a', 'c', 'd', 'e', 'j', 'k', 'r', 't', 'y', 'i', 'u', 's', 'e', 'x', 's', 'u', 'x'};
System.out.println(a);
sort(a);
System.out.println(a);
}
publicstaticvoidsort(char[] a) {
intR = 26;
int[] count = newint[R + 1];
intN = a.length;
char[] aux = newchar[N];
for (inti = 0; i < N; i++)
count[a[i] - 'a' + 1]++;
for (intr = 0; r < R; r++)
count[r + 1] += count[r];
for (inti = 0; i < N; i++)
aux[count[a[i] - 'a']++] = a[i];
for (inti = 0; i < N; i++)
a[i] = aux[i];
}
}