- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeWayStringQuicksort.java
More file actions
Latest commit
55 lines (43 loc) · 1.33 KB
/
Copy pathThreeWayStringQuicksort.java
File metadata and controls
55 lines (43 loc) · 1.33 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
50
51
52
53
54
55
packagestring;
publicclassThreeWayStringQuicksort {
publicstaticvoidsort(String[] a) {
sort(a, 0, a.length - 1, 0);
}
privatestaticvoidsort(String[] a, intlo, inthi, intd) {
if (hi <= lo) {
return;
}
intlt = lo;
intgt = hi;
intv = charAt(a[lo], d);
inti = lo + 1;
while (i <= gt) {
intt = charAt(a[i], d);
if (t < v) exch(a, lt++, i++);
elseif (t > v) exch(a, i, gt--);
elsei++;
}
sort(a, lo, lt - 1, d);
if (v >= 0) sort(a, lt, gt, d + 1);
sort(a, gt + 1, hi, d);
}
privatestaticintcharAt(Strings, intd) {
if (d < s.length()) returns.charAt(d);
return -1;
}
privatestaticvoidexch(String[] a, intx, inty) {
Stringtemp = a[x];
a[x] = a[y];
a[y] = temp;
}
publicstaticvoidmain(String[] args) {
String[] a = {"she", "sells", "seashells", "by", "the", "shore", "the", "seashells", "are", "shellish", "and", "made", "from", "shellfish"};
for (Strings : a)
System.out.print(s + " ");
System.out.println();
sort(a);
for (Strings : a)
System.out.print(s + " ");
System.out.println();
}
}