Skip to content

Commit c7c2d88

Browse files
committed
version 3.11
1 parent 32695de commit c7c2d88

File tree

10 files changed

+29
-18
lines changed

10 files changed

+29
-18
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) 2019 w0rthy
4-
Copyright (c) 2019 MusicTheorist
4+
Copyright (c) 2020 MusicTheorist
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ java -cp bin;lib/classgraph-4.8.47.jar main.ArrayVisualizer
2323
- Toggle Timo Bingmann's "end sweep" animation
2424
- Refactored / optimized code
2525

26+
## 6/2/2020 - Version 3.11
27+
_changelog coming soon_
28+
2629
## 5/30/2020 - Version 3.1
2730
- Error messages with detailed information will now appear within the program!
2831
- Sound effects are now consistent on all platforms

dist/arrayVisualizer.jar

3.86 KB
Binary file not shown.

src/prompts/SortPrompt.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import threads.RunAllSorts;
1515
import threads.RunComparisonSort;
1616
import threads.RunDistributionSort;
17+
import threads.RunHybridSorts;
1718

1819
/*
1920
*

src/sorts/FlippedMinHeapSort.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
modified by Lucy Phipps from ../templates/HeapSorting.java and MinHeapSort.java
2323
the only real changes are subtracting every array access from (length - 1)
2424
and removing the Writes.reverse() at the end
25-
the rest is just compacting tbe code a bit
25+
the rest is just compacting the code a bit
2626
*/
2727

2828
final public class FlippedMinHeapSort extends Sort {
@@ -45,8 +45,11 @@ private void siftDown(int[] array, int length, int root, int dist) {
4545
if (leaf < dist && Reads.compare(array[length - leaf], array[length - leaf - 1]) == 1) {
4646
leaf++;
4747
}
48+
Highlights.markArray(1, length - root);
49+
Highlights.markArray(2, length - leaf);
50+
Delays.sleep(1);
4851
if (Reads.compare(array[length - root], array[length - leaf]) == 1) {
49-
Writes.swap(array, length - root, length - leaf, 1, true, false);
52+
Writes.swap(array, length - root, length - leaf, 0, true, false);
5053
root = leaf;
5154
} else break;
5255
}

src/sorts/PatienceSort.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void runSort(int[] array, int length, int bucketCount) {
8181
Pile newPile = new Pile();
8282

8383
Highlights.markArray(2, x);
84-
Writes.mockWrite(length, newPile.size(), array[x], 1);
84+
Writes.mockWrite(length, Math.min(newPile.size(), length - 1), array[x], 1);
8585

8686
newPile.push(array[x]);
8787

@@ -91,11 +91,11 @@ public void runSort(int[] array, int length, int bucketCount) {
9191
}
9292
if (i < 0) i = ~i;
9393
if (i != piles.size()) {
94-
Writes.mockWrite(length, piles.get(i).size(), array[x], 0);
94+
Writes.mockWrite(length, Math.min(piles.get(i).size(), length - 1), array[x], 0);
9595
piles.get(i).push(array[x]);
9696
}
9797
else {
98-
Writes.mockWrite(length, piles.size(), newPile.get(0), 0);
98+
Writes.mockWrite(length, Math.min(piles.size(), length - 1), newPile.get(0), 0);
9999
piles.add(newPile);
100100
}
101101
}
@@ -106,14 +106,14 @@ public void runSort(int[] array, int length, int bucketCount) {
106106
PriorityQueue<Pile> heap = new PriorityQueue<>(piles);
107107

108108
for (int c = 0; c < length; c++) {
109-
Writes.mockWrite(length, heap.size(), 0, 0);
109+
Writes.mockWrite(length, Math.min(heap.size(), length - 1), 0, 0);
110110
Pile smallPile = heap.poll();
111111

112-
Writes.mockWrite(length, smallPile.size(), 0, 0);
112+
Writes.mockWrite(length, Math.min(smallPile.size(), length - 1), 0, 0);
113113
Writes.write(array, c, smallPile.pop(), 1, true, false);
114114

115115
if (!smallPile.isEmpty()) {
116-
Writes.mockWrite(length, heap.size(), smallPile.get(0), 0);
116+
Writes.mockWrite(length, Math.min(heap.size(), length - 1), smallPile.get(0), 0);
117117
heap.offer(smallPile);
118118
}
119119
}

src/templates/HeapSorting.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ private void siftDown(int[] array, int root, int dist, int start, double sleep,
3333
if (leaf < dist && Reads.compare(array[start + leaf - 1], array[start + leaf]) == compareVal) {
3434
leaf++;
3535
}
36+
Highlights.markArray(1, start + root - 1);
37+
Highlights.markArray(2, start + leaf - 1);
38+
Delays.sleep(sleep);
3639
if (Reads.compare(array[start + root - 1], array[start + leaf - 1]) == compareVal) {
37-
Writes.swap(array, start + root - 1, start + leaf - 1, sleep, true, false);
40+
Writes.swap(array, start + root - 1, start + leaf - 1, 0, true, false);
3841
root = leaf;
3942
}
4043
else break;

src/templates/MultipleSortThread.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import utils.Delays;
66
import utils.Highlights;
77
import utils.Reads;
8+
import utils.Shuffles;
89
import utils.Sounds;
910
import utils.Timer;
1011
import utils.Writes;

src/threads/RunExchangeSorts.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ public void run() {
9090
//RunExchangeSorts.this.RunIndividualSort(BinaryGnomeSort, 0, array, 128, 0.002);
9191
RunExchangeSorts.this.RunIndividualSort(CombSort, 0, array, 1024, 1);
9292
RunExchangeSorts.this.RunIndividualSort(CircleSort, 0, array, 1024, 1);
93-
RunExchangeSorts.this.RunIndividualSort(LLQuickSort, 0, array, 2048, 1);
93+
RunExchangeSorts.this.RunIndividualSort(LLQuickSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 150 : 1.5);
9494
RunExchangeSorts.this.RunIndividualSort(LRQuickSort, 0, array, 2048, 1);
95-
RunExchangeSorts.this.RunIndividualSort(DualPivotQuickSort, 0, array, 2048, 1);
96-
RunExchangeSorts.this.RunIndividualSort(StableQuickSort, 0, array, 2048, 1);
95+
RunExchangeSorts.this.RunIndividualSort(DualPivotQuickSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 100 : 1);
96+
RunExchangeSorts.this.RunIndividualSort(StableQuickSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 100 : 1);
9797

9898
ArrayVisualizer.setCategory("Run Exchange Sorts");
9999
ArrayVisualizer.setHeading("Done");
@@ -150,10 +150,10 @@ public void run() {
150150
//RunExchangeSorts.this.RunIndividualSort(BinaryGnomeSort, 0, array, 128, 0.002);
151151
RunExchangeSorts.this.RunIndividualSort(CombSort, 0, array, 1024, 1);
152152
RunExchangeSorts.this.RunIndividualSort(CircleSort, 0, array, 1024, 1);
153-
RunExchangeSorts.this.RunIndividualSort(LLQuickSort, 0, array, 2048, 1.5);
153+
RunExchangeSorts.this.RunIndividualSort(LLQuickSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 150 : 1.5);
154154
RunExchangeSorts.this.RunIndividualSort(LRQuickSort, 0, array, 2048, 1);
155-
RunExchangeSorts.this.RunIndividualSort(DualPivotQuickSort, 0, array, 2048, 1);
156-
RunExchangeSorts.this.RunIndividualSort(StableQuickSort, 0, array, 2048, 1);
155+
RunExchangeSorts.this.RunIndividualSort(DualPivotQuickSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 100 : 1);
156+
RunExchangeSorts.this.RunIndividualSort(StableQuickSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 100 : 1);
157157

158158
ArrayManager.toggleMutableLength(true);
159159
}

src/threads/RunHybridSorts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void run() {
8585
RunHybridSorts.this.RunIndividualSort(HybridCombSort, 0, array, 1024, 1);
8686
RunHybridSorts.this.RunIndividualSort(IntroCircleSort, 0, array, 1024, 1);
8787
RunHybridSorts.this.RunIndividualSort(BinaryMergeSort, 0, array, 2048, 1);
88-
RunHybridSorts.this.RunIndividualSort(WeaveMergeSort, 0, array, 2048, 1.25);
88+
RunHybridSorts.this.RunIndividualSort(WeaveMergeSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 12.5 : 1.25);
8989
RunHybridSorts.this.RunIndividualSort(TimSort, 0, array, 2048, 1);
9090
RunHybridSorts.this.RunIndividualSort(CocktailMergeSort, 0, array, 2048, 1);
9191
RunHybridSorts.this.RunIndividualSort(WikiSort, 0, array, 2048, 1);
@@ -148,7 +148,7 @@ public void run() {
148148
RunHybridSorts.this.RunIndividualSort(HybridCombSort, 0, array, 1024, 1);
149149
RunHybridSorts.this.RunIndividualSort(IntroCircleSort, 0, array, 1024, 1);
150150
RunHybridSorts.this.RunIndividualSort(BinaryMergeSort, 0, array, 2048, 1);
151-
RunHybridSorts.this.RunIndividualSort(WeaveMergeSort, 0, array, 2048, 1.25);
151+
RunHybridSorts.this.RunIndividualSort(WeaveMergeSort, 0, array, 2048, ArrayManager.getShuffle() == ArrayManager.getShuffle().REVERSE ? 12.5 : 1.25);
152152
RunHybridSorts.this.RunIndividualSort(TimSort, 0, array, 2048, 1);
153153
RunHybridSorts.this.RunIndividualSort(CocktailMergeSort, 0, array, 2048, 1);
154154
RunHybridSorts.this.RunIndividualSort(WikiSort, 0, array, 2048, 1);

0 commit comments

Comments
 (0)