Skip to content

Commit

Permalink
Add TwinSort to Run All (and improve visualization of NaturalMergeSort)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Feb 2, 2021
1 parent bf7fe3e commit b0172d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/sorts/merge/NaturalMergeSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sorts.templates.Sort;

final public class NaturalMergeSort extends Sort {
int[] merged;

public NaturalMergeSort(ArrayVisualizer arrayVisualizer) {
super(arrayVisualizer);
this.setSortListName("Natural Merge");
Expand All @@ -19,7 +21,6 @@ public NaturalMergeSort(ArrayVisualizer arrayVisualizer) {
}

private void merge(int[] arr, int left, int right, int stop) {
int[] merged = Writes.createExternalArray(stop - left);
boolean first = true;
int index = 0;
int start = 0;
Expand All @@ -41,13 +42,11 @@ private void merge(int[] arr, int left, int right, int stop) {
Highlights.clearMark(2);
for (int i = start; i < index; i++)
Writes.write(arr, i + origLeft, merged[i], 1, true, false);
for (int i = start; i < index; i++)
merged[i] = 0;
Writes.deleteExternalArray(merged);
}

@Override
public void runSort(int[] arr, int length, int bucketCount) {
merged = Writes.createExternalArray(length);
boolean done = false;
int start = 0;
int stop = length - 1;
Expand Down Expand Up @@ -75,5 +74,6 @@ public void runSort(int[] arr, int length, int bucketCount) {
stop = left;
}
}
Writes.deleteExternalArray(merged);
}
}
11 changes: 7 additions & 4 deletions src/threads/RunMergeSorts.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ of this software and associated documentation files (the "Software"), to deal
final public class RunMergeSorts extends MultipleSortThread {
private Sort MergeSort;
private Sort BottomUpMergeSort;
private Sort NaturalMergeSort;
private Sort PartialMergeSort;
private Sort TwinSort;
private Sort NaturalMergeSort;
private Sort PDMergeSort;
private Sort InPlaceMergeSort;
private Sort ImprovedInPlaceMergeSort;
Expand All @@ -50,13 +51,14 @@ final public class RunMergeSorts extends MultipleSortThread {

public RunMergeSorts(ArrayVisualizer arrayVisualizer) {
super(arrayVisualizer);
this.sortCount = 15;
this.sortCount = 16;
this.categoryCount = this.sortCount;

MergeSort = new MergeSort(this.arrayVisualizer);
BottomUpMergeSort = new BottomUpMergeSort(this.arrayVisualizer);
NaturalMergeSort = new NaturalMergeSort(this.arrayVisualizer);
PartialMergeSort = new PartialMergeSort(this.arrayVisualizer);
TwinSort = new TwinSort(this.arrayVisualizer);
NaturalMergeSort = new NaturalMergeSort(this.arrayVisualizer);
PDMergeSort = new PDMergeSort(this.arrayVisualizer);
InPlaceMergeSort = new InPlaceMergeSort(this.arrayVisualizer);
ImprovedInPlaceMergeSort = new ImprovedInPlaceMergeSort(this.arrayVisualizer);
Expand All @@ -74,8 +76,9 @@ public RunMergeSorts(ArrayVisualizer arrayVisualizer) {
protected synchronized void executeSortList(int[] array) throws Exception {
RunMergeSorts.this.runIndividualSort(MergeSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(BottomUpMergeSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(NaturalMergeSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(PartialMergeSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(TwinSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(NaturalMergeSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(PDMergeSort, 0, array, 2048, 1, false);
RunMergeSorts.this.runIndividualSort(InPlaceMergeSort, 0, array, 2048, 1.5, false);
RunMergeSorts.this.runIndividualSort(ImprovedInPlaceMergeSort, 0, array, 2048, 1.5, false);
Expand Down

0 comments on commit b0172d4

Please sign in to comment.