Skip to content

Commit 1c0c4b0

Browse files
committed
2018 update
1 parent 2ed5e08 commit 1c0c4b0

22 files changed

+612
-357
lines changed

dist/ArrayVisualizer.jar

10.9 KB
Binary file not shown.

src/Analysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static int analyzemax() throws Exception{
4040
a=array[i];
4141
marked.set(1,i);
4242
aa++;
43-
sleep(1);
43+
sleep(1.0);
4444
}
4545
return a;
4646
}

src/ArrayVisualizer.java

Lines changed: 325 additions & 227 deletions
Large diffs are not rendered by default.

src/BogoSort.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@
55

66
public class BogoSort {
77
public static boolean bogoIsSorted(int[] arr){
8-
for(int i = 1; i < arr.length; i++)
8+
for(int i = 1; i < arr.length; i++){
9+
comps++;
10+
aa++;
11+
marked.set(1, i);
12+
marked.set(2,i-1);
13+
sleep(1);
914
if(arr[i]<arr[i-1])
1015
return false;
16+
}
1117
return true;
1218
}
1319

1420
public static void bogoSort(){
1521
while(!bogoIsSorted(array)){
16-
for(int i = 0; i < array.length; i++)
22+
for(int i = 0; i < array.length; i++){
1723
swap(array, i, (int)(Math.random()*array.length));
18-
//sleep(100.0);
24+
sleep(1);
25+
}
1926
}
2027
}
2128

src/BubbleSort.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
public class BubbleSort {
1515
public static void bubbleSort() throws Exception{
1616
for(int i = array.length-1; i > 0; i--){
17-
marked.set(0,i);
18-
for(int j = 0; j < i; j++)
17+
for(int j = 0; j < i; j++){
18+
sleep(0.005);
1919
if(array[j]>array[j+1]){
2020
comps++;
21-
swap(array, j, j+1, Math.max(j%50-48,0));
21+
swap(array, j, j+1,0.01);
22+
}else{
23+
marked.set(1,j+1);
24+
marked.set(2,-5);
2225
}
26+
}
27+
//marked.set(0,i);
2328
}
2429
}
2530
}

src/CocktailShaker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public static void cocktailShakerSort(){
1818
for(int j = i; j < array.length-i-1; j++){
1919
comps++;
2020
if(array[j]>array[j+1])
21-
swap(array, j, j+1, j%40/39);
21+
swap(array, j, j+1, 0.022);
2222
}
2323
for(int j = array.length-i-1; j > i; j--){
2424
comps++;
2525
if(array[j]<array[j-1])
26-
swap(array, j, j-1, j%40/39);
26+
swap(array, j, j-1, 0.022);
2727
}
2828
i++;
2929
}

src/CountingSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void countingSort() throws Exception {
1717
int[] counts = new int[max+1];
1818
for(int i = 0; i < array.length; i++){
1919
marked.set(1,i);
20-
sleep(1);
20+
sleep(2);
2121
counts[array[i]]++;
2222
aa++;
2323
}
@@ -29,7 +29,7 @@ public static void countingSort() throws Exception {
2929
aa++;
3030
counts[x]--;
3131
marked.set(1, i);
32-
sleep(1);
32+
sleep(2);
3333
}
3434
}
3535
}

src/DoubleSelection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ public static void doubleSelectionSort(int[] arr) {
2020
int biggest = 0;
2121
while(left<=right){
2222
for(int i = left; i <= right; i++){
23+
marked.set(1,i);
2324
if(arr[i]>arr[biggest])
2425
biggest = i;
2526
if(arr[i]<arr[smallest])
2627
smallest = i;
2728
comps+=2;
29+
sleep(0.02);
2830
}
2931
if(biggest==left)
3032
biggest = smallest;
31-
swap(arr, left, smallest, sleepTime(0.01));
32-
swap(arr, right, biggest, sleepTime(0.01));
33+
swap(arr, left, smallest, 0.01);
34+
swap(arr, right, biggest, 0.01);
3335
left++;
3436
right--;
3537
smallest = left;

src/GravitySort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public static void gravitySort() throws Exception {
4141
for(int y = 0; y < abacus[0].length; y++)
4242
count+=abacus[x][y];
4343
array[x] = count;
44+
sleep(0.002);
4445
}
46+
marked.set(1,array.length-i-1);
4547
sleep(2);
4648
}
4749
}

src/InsertionSort.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public static void insertionSort() {
1616
int pos;
1717
for(int i = 1; i < array.length; i++){
1818
pos = i;
19-
//marked.set(0, i);
19+
marked.set(1, i);
20+
marked.set(2, -5);
2021
while(pos>0&&array[pos]<=array[pos-1]){
21-
comps+=2;
22-
swap(array, pos, pos-1,Math.max(pos%50-48,0));
23-
pos--;
22+
comps+=2;
23+
swap(array, pos, pos-1, 0.02);
24+
pos--;
2425
}
2526
}
2627
}
@@ -29,7 +30,8 @@ public static void insertionSort(int start, int end, double slpamt) {
2930
int pos;
3031
for(int i = start; i < end; i++){
3132
pos = i;
32-
//marked.set(0, i);
33+
marked.set(1, i);
34+
marked.set(2, -5);
3335
while(pos>start&&array[pos]<=array[pos-1]){
3436
comps+=2;
3537
swap(array, pos, pos-1);

0 commit comments

Comments
 (0)