-
Notifications
You must be signed in to change notification settings - Fork 0
/
franceschinipoc.java
128 lines (93 loc) · 3.37 KB
/
franceschinipoc.java
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package sorts.Customs;
import java.security.InvalidKeyException;
import main.ArrayVisualizer;
import sorts.templates.Sort;
final public class franceschinipoc extends Sort {
public franceschinipoc(ArrayVisualizer arrayVisualizer) {
super(arrayVisualizer);
this.setSortListName("AAAlog");
this.setRunAllSortsName("AAAlog");
this.setRunSortName("AAAlog");
this.setCategory("custom");
this.setComparisonBased(true);
this.setBucketSort(false);
this.setRadixSort(false);
this.setUnreasonablySlow(false);
this.setUnreasonableLimit(0);
this.setBogoSort(false);
}
public int partition(int[] array, int median, int length, int[] aux){
int lesserpointer = 0;
int greaterpointer = 0;
for(int i = 0; i <= length; i++){
if(array[i] > median){
aux[greaterpointer] = array[i];
greaterpointer++;
} else {
array[lesserpointer] = array[i];
lesserpointer++;
}
Delays.sleep(0.25);
}
for(int i = length; i >= lesserpointer; i--){
array[i] = aux[greaterpointer];
greaterpointer--;
Delays.sleep(0.25);
}
return lesserpointer;
}
public void cks(int[] array, int middle, int length, int[] aux){ //cks = collect keys stably
int i = 0;
int k = middle;
array[i] = array[k];
i++;
k++;
while(k < length && i <= middle){
if(!linearisElemof(array, 0, i, array[k])){
Writes.swap(array, i, k, 0.25, true, false);
i++;
}
Delays.sleep(0.5);
k++;
}
}
public boolean linearisElemof(int[] array, int start, int end, int element){
for(int i = start; i <= end; i++){
if(array[i] == element){
System.out.print("t");
Highlights.markArray(1, i);
return true;
}
}
System.out.print("f");
return false;
}
public int pivotpartition(int[] array, int median, int length, int[] aux, int start){
int lesserpointer = start;
int greaterpointer = 0;
for(int i = start; i <= length; i++){
if(array[i] > median){
aux[greaterpointer] = array[i];
greaterpointer++;
} else {
array[lesserpointer] = array[i];
lesserpointer++;
}
Delays.sleep(0.75);
}
for(int i = 0; i<greaterpointer; i++){
array[lesserpointer] = aux[i];
lesserpointer++;
Delays.sleep(0.75);
}
return lesserpointer;
}
@Override
public void runSort(int[] array, int currentLength, int bucketCount) {
int[] aux = Writes.createExternalArray(currentLength);
int middle = partition(array, (currentLength-1)/6, currentLength, aux);
cks(array, middle, currentLength-1, aux);
pivotpartition(array, (currentLength-1)/6, currentLength-1, aux, middle);
Writes.deleteExternalArray(aux);
}
}