forked from w0rthy/ArrayVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShatterSorts.java
More file actions
53 lines (49 loc) · 1.68 KB
/
ShatterSorts.java
File metadata and controls
53 lines (49 loc) · 1.68 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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package array.visualizer;
import static array.visualizer.ArrayVisualizer.*;
import static array.visualizer.Transcriptions.*;
import java.util.ArrayList;
/**
*
* @author S630690
*/
public class ShatterSorts {
public static void shatterPartition(int num) throws Exception {
int shatters = (int)Math.ceil(array.length/(double)num);
ArrayList<Integer>[] registers = new ArrayList[shatters];
for(int i = 0; i < shatters; i++)
registers[i] = new ArrayList<Integer>();
for(int i = 0; i < array.length; i++)
registers[array[i]/num].add(array[i]);
transcribe(registers, array);
}
public static void shatterSort(int num) throws Exception {
int shatters = (int)Math.ceil(array.length/(double)num);
shatterPartition(num);
int[] tmp = new int[num];
for(int i = 0; i < shatters; i++){
for(int j = 0; j < num; j++){
if(i*num+j>=array.length)
tmp[j] = -1;
else
tmp[j]=array[i*num+j];
}
for(int j = 0; j < tmp.length; j++){
if(i*num+(tmp[j]%num)>=array.length || tmp[j] == -1)
break;
array[i*num+(tmp[j]%num)]=tmp[j];
aa++;
marked.set(1, i*num+(tmp[j]%num));
sleep(sleepTime(0.02));
}
}
}
public static void simpleShatterSort(int num, int rate) throws Exception {
for(int i = num; i > 1; i = i/rate)
shatterPartition(i);
shatterPartition(1);
}
}