forked from w0rthy/ArrayVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadixLSDInPlace.java
More file actions
32 lines (29 loc) · 1.04 KB
/
RadixLSDInPlace.java
File metadata and controls
32 lines (29 loc) · 1.04 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
package array.visualizer;
import static array.visualizer.Analysis.*;
import static array.visualizer.ArrayVisualizer.*;
import static array.visualizer.Swaps.*;
public class RadixLSDInPlace {
public static void inPlaceRadixLSDSort(int radix)throws Exception{
int pos = 0;
int[] vregs = new int[radix-1];
int maxpower = analyze(radix);
for(int p = 0; p <= maxpower; p++){
for(int i = 0; i < vregs.length; i++)
vregs[i]=array.length-1;
pos = 0;
for(int i = 0; i < array.length; i++){
int digit = getDigit(array[pos], p, radix);
if(digit==0) {
pos++;
marked.set(0, pos);
} else {
for(int j = 0; j<vregs.length;j++)
marked.set(j+1,vregs[j]);
swapUpTo(pos,vregs[digit-1]);
for(int j = digit-1; j > 0; j--)
vregs[j-1]--;
}
}
}
}
}