-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: fluffyyboii <[email protected]>
- Loading branch information
1 parent
e11852c
commit 6e682ee
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package sorts.select; | ||
|
||
import main.ArrayVisualizer; | ||
import sorts.templates.Sort; | ||
|
||
final public class BaseNMaxHeapSort extends Sort { | ||
public BaseNMaxHeapSort(ArrayVisualizer arrayVisualizer) { | ||
super(arrayVisualizer); | ||
this.setSortListName("Base-N Max Heap"); | ||
this.setRunAllSortsName("Base-N Max Heap Sort"); | ||
this.setRunSortName("Base-N Max Heapsort"); | ||
this.setCategory("Selection Sorts"); | ||
this.setComparisonBased(true); | ||
this.setBucketSort(true); | ||
this.setRadixSort(false); | ||
this.setUnreasonablySlow(false); | ||
this.setUnreasonableLimit(0); | ||
this.setBogoSort(false); | ||
} | ||
|
||
private void siftDown(int[] arr, int base, int node, int stop) { | ||
int left = node * base + 1; | ||
if (left < stop) { | ||
int maxIndex = left; | ||
for (int i = left + 1; i < left + base; i++) { | ||
if (i >= stop) | ||
break; | ||
if (Reads.compareValues(arr[maxIndex], arr[i]) == -1) | ||
maxIndex = i; | ||
} | ||
if (Reads.compareValues(arr[node], arr[maxIndex]) == -1) { | ||
Writes.swap(arr, node, maxIndex, 1, true, false); | ||
this.siftDown(arr, base, maxIndex, stop); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void runSort(int[] arr, int length, int base) { | ||
for (int i = length - 1; i > -1; i--) | ||
this.siftDown(arr, base, i, length); | ||
for (int i = length - 1; i > 0; i--) { | ||
Writes.swap(arr, 0, i, 1, true, false); | ||
this.siftDown(arr, base, 0, i); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters