From a422b86fc0caa7143e004e37d00731df08120611 Mon Sep 17 00:00:00 2001 From: Joel <30326841+McDude73@users.noreply.github.com> Date: Fri, 12 Jun 2020 11:35:06 -0600 Subject: [PATCH 1/8] 2 New Sorts Implemented two new sorts: (Iterative Merge Sort) (Iterative Quick Sort) Each have descriptions in the files of how they should work. --- src/sorts/IterativeMergeSort.java | 104 ++++++++++++++++++++++++++++++ src/sorts/IterativeQuickSort.java | 95 +++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 src/sorts/IterativeMergeSort.java create mode 100644 src/sorts/IterativeQuickSort.java diff --git a/src/sorts/IterativeMergeSort.java b/src/sorts/IterativeMergeSort.java new file mode 100644 index 00000000..7941814d --- /dev/null +++ b/src/sorts/IterativeMergeSort.java @@ -0,0 +1,104 @@ +package sorts; + +import templates.Sort; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Iterative Merge Sort goes through multiple iterations of creating a sub-array on two + * different sides of what will become a merged array. The arrays are created multiple + * times, however each pass through the array will double the sub-array size. + * + * Once each value is written to the sub-arrays accordingly, then the elements + * are compared to each other based on what's in each sub-array + * via it's value, and is then written to the main array. + * + * Any leftover pieces from the sub-arrays are written into the main array last. + * + * >> Original source(s): + * >> https://www.geeksforgeeks.org/iterative-merge-sort/ + * + * >> Imported by Joel "McDude73" Zaleschuk + */ + +final public class IterativeMergeSort extends Sort { + public IterativeMergeSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Iterative Merge"); + this.setRunAllID("Iterative Merge Sort"); + this.setReportSortID("Iterative Mergesort"); + this.setCategory("Merge Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(false); + this.setUnreasonableLimit(0); + this.isBogoSort(false); + } + + private void merge(int[] array, int left, int middle, int right) { + int i, j, k; + int n1 = middle - left + 1; + int n2 = right - middle; + + int[] leftArr = new int[n1]; + int[] rightArr = new int[n2]; + + for(i=0;i> Original source(s): + * >> https://www.geeksforgeeks.org/iterative-quick-sort/ + * + * >> Imported by Joel "McDude73" Zaleschuk + */ + +final public class IterativeQuickSort extends Sort { + public IterativeQuickSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Iterative Quick"); + this.setRunAllID("Iterative Quick Sort"); + this.setReportSortID("Iterative Quicksort"); + this.setCategory("Exchange Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(false); + this.setUnreasonableLimit(0); + this.isBogoSort(false); + } + + private int partition(int[] array, int lowValue, int highValue) { + int pivot = array[highValue]; + + int i = lowValue - 1; + for(int j=lowValue;j<=highValue-1;j++) { + if(Reads.compare(array[j], pivot) <= 0) { + i++; + Writes.swap(array, i, j, 0.75, true, false); + } + } + Writes.swap(array, i+1, highValue, 0.75, true, false); + return i + 1; + } + + private void quickSort(int[] array, int startIndex, int endIndex) { + int[] stack = new int[endIndex - startIndex + 1]; + + int top = -1; + + Writes.write(stack, ++top, startIndex, 0, true, true); + Writes.write(stack, ++top, endIndex, 0, true, true); + + while(top >= 0) { + endIndex = stack[top--]; + startIndex = stack[top--]; + + int p = partition(array, startIndex, endIndex); + + if(Reads.compare(p-1, startIndex) == 1) { + Writes.write(stack, ++top, startIndex, 0, false, true); + Writes.write(stack, ++top, p-1, 0, false, true); + } + + if(Reads.compare(p+1, endIndex) == -1) { + Writes.write(stack, ++top, p+1, 0, false, true); + Writes.write(stack, ++top, endIndex, 0, false, true); + } + } + } + + @Override + public void runSort(int[] array, int length, int bucketCount) { + quickSort(array, 0, length-1); + } +} \ No newline at end of file From 4da9439a151e90b94d3311925b8b14b589a1ec50 Mon Sep 17 00:00:00 2001 From: Joel <30326841+McDude73@users.noreply.github.com> Date: Sun, 14 Jun 2020 16:18:19 -0600 Subject: [PATCH 2/8] More Sorts Added More Sorts for the Visualizer --- src/sorts/BingoSort.java | 80 +++++++++++++++++++++++++ src/sorts/GrateSort.java | 59 +++++++++++++++++++ src/sorts/SlideSort.java | 122 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 src/sorts/BingoSort.java create mode 100644 src/sorts/GrateSort.java create mode 100644 src/sorts/SlideSort.java diff --git a/src/sorts/BingoSort.java b/src/sorts/BingoSort.java new file mode 100644 index 00000000..a4a5c15d --- /dev/null +++ b/src/sorts/BingoSort.java @@ -0,0 +1,80 @@ +package sorts; + +import templates.Sort; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Bingo Sort is a variant of Selection Sort which looks through all elements, using the + * element with the maximum VALUE instead of the item to be swapped instead of the item. + * + * This is best suited to use when there are duplicate values in the array because the + * sort will run quicker (similar to Counting Sort) - running on O(n+m^2) best case scenario, + * otherwise it will run at O(n*m) time complexity, + * where "m" is the amount of unique values in the array. + * + * >> Original source(s): + * >> https://en.wikipedia.org/wiki/Selection_sort#Variants + * >> https://xlinux.nist.gov/dads/HTML/bingosort.html + * + * >> Imported and Translated (from Pascal) by Joel "McDude73" Zaleschuk + */ + +final public class BingoSort extends Sort { + public BingoSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Bingo"); + this.setRunAllID("Bingo Sort"); + this.setReportSortID("Bingosort"); + this.setCategory("Selection Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(false); + this.setUnreasonableLimit(0); + this.isBogoSort(false); + } + + @Override + public void runSort(int[] array, int length, int bucketCount) { + int maximum = length - 1; + int next = array[maximum]; + + for(int i=maximum-1;i>=0;i--) { + if(array[i] > next) { + next = array[i]; + } + } + while(maximum > 0 && array[maximum] == next) { + maximum--; + } + while(maximum > 0) { + int val = next; + next = array[maximum]; + + for(int j=maximum-1;j>=0;j--) { + + Highlights.markArray(1, array[j]); + Highlights.markArray(2, val); + + if(Reads.compare(array[j], val) == 0) { + Writes.swap(array, j, maximum, 0.02, true, false); + maximum--; + + } + else { + if(array[j] > next) { + next = array[j]; + } + } + Delays.sleep(0.01); + } + while(maximum > 0 && array[maximum] == next) { + maximum--; + } + } + } +} \ No newline at end of file diff --git a/src/sorts/GrateSort.java b/src/sorts/GrateSort.java new file mode 100644 index 00000000..d0b4e84f --- /dev/null +++ b/src/sorts/GrateSort.java @@ -0,0 +1,59 @@ +package sorts; + +import templates.Sort; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Grate Sort will commit a pass every time the array is not considered sorted. + * What it will do is it will start by comparing the element selected from the pass to the + * right-most element. + * + * It will swap the elements if the right-most element is smaller than the one on the pass. + * It will check the element one to the left from where the last element was checked until + * the right marker reaches the element being checked during the pass. + * + * If at any point a swap was made, another pass must take place after the current one. + * + * >> Idea from EilrahcF#1021 + * >> Scripted by Joel "McDude_73" Zaleschuk + */ + +final public class GrateSort extends Sort { + public GrateSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Grate"); + this.setRunAllID("Grate Sort"); + this.setReportSortID("Grate Sort"); + this.setCategory("Exchange Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(true); + this.setUnreasonableLimit(512); + this.isBogoSort(false); + } + + @Override + public void runSort(int[] array, int currentLength, int bucketCount) { + boolean sorted = false; + while(!sorted) { + sorted = true; + for(int i=0;ii;j--) { + Highlights.markArray(1, i); + Highlights.markArray(2, j); + Delays.sleep(0.25); + if(Reads.compare(array[i], array[j]) > 0) { + sorted = false; + Writes.swap(array, i, j, 0.1, true, false); + break; + } + } + } + } + } +} \ No newline at end of file diff --git a/src/sorts/SlideSort.java b/src/sorts/SlideSort.java new file mode 100644 index 00000000..fd3001e5 --- /dev/null +++ b/src/sorts/SlideSort.java @@ -0,0 +1,122 @@ +package sorts; + +import java.util.ArrayList; + +import templates.InsertionSorting; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * The idea is to take the size of the array and divide it by four, using this as a key number for later. + * Perform an Insertion Sort on all quarters of the array, then write the results to + * a sub-array. + * + * The sub-arrays will determine which element is the largest out of the 4 (where the key number comes in), + * by performing a basic Selection Sort between all 4 top elements of each of the 4 sub-arrays. + * + * Once an element is used placed into the main array for the final results, it will remove + * the largest number and continue downwards until there are no elements left in all subarrays. + * + * >> Idea from EilrahcF#1021 + * >> Scripted by Joel "McDude_73" Zaleschuk + */ + +final public class SlideSort extends InsertionSorting { + public SlideSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Slide"); + this.setRunAllID("Slide Sort"); + this.setReportSortID("Slide Sort"); + this.setCategory("Hybrid Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(false); + this.setUnreasonableLimit(0); + this.isBogoSort(false); + } + + @Override + public void runSort(int[] array, int currentLength, int bucketCount) { + ArrayList sub1 = new ArrayList<>(); + ArrayList sub2 = new ArrayList<>(); + ArrayList sub3 = new ArrayList<>(); + ArrayList sub4 = new ArrayList<>(); + // Commence Insertion Sorting + if(currentLength < 8) { + this.insertionSort(array, 0, currentLength, 0.333, false); + return; + } + int div = currentLength / 4; + + for(int i=0;i=0;a--) { + if(sub1.size() >= 1) { + largest = sub1.get(sub1.size()-1); + if(sub2.size() >= 1 && Reads.compare(largest, sub2.get(sub2.size()-1)) < 0) { + largest = sub2.get(sub2.size()-1); + } + if(sub3.size() >= 1 && Reads.compare(largest, sub3.get(sub3.size()-1)) < 0) { + largest = sub3.get(sub3.size()-1); + } + if(sub4.size() >= 1 && Reads.compare(largest, sub4.get(sub4.size()-1)) < 0) { + largest = sub4.get(sub4.size()-1); + } + } else if(sub2.size() >= 1) { + largest = sub2.get(sub2.size()-1); + if(sub3.size() >= 1 && Reads.compare(largest, sub3.get(sub3.size()-1)) < 0) { + largest = sub3.get(sub3.size()-1); + } + if(sub4.size() >= 1 && Reads.compare(largest, sub4.get(sub4.size()-1)) < 0) { + largest = sub4.get(sub4.size()-1); + } + } else if(sub3.size() >= 1) { + largest = sub3.get(sub3.size()-1); + if(sub4.size() >= 1 && Reads.compare(largest, sub4.get(sub4.size()-1)) < 0) { + largest = sub4.get(sub4.size()-1); + } + } else if(sub4.size() >= 1) { + largest = sub4.get(sub4.size()-1); + } + + // Separator + Writes.write(array, a, largest, 0.75, true, false); + if((sub1.size() >= 1) && largest == sub1.get(sub1.size()-1)) sub1.remove(sub1.size()-1); + else if((sub2.size() >= 1) && largest == sub2.get(sub2.size()-1)) sub2.remove(sub2.size()-1); + else if((sub3.size() >= 1) && largest == sub3.get(sub3.size()-1)) sub3.remove(sub3.size()-1); + else if((sub4.size() >= 1) && largest == sub4.get(sub4.size()-1)) sub4.remove(sub4.size()-1); + } + } +} \ No newline at end of file From 4e686f5fcd09c276df3f58c728f1c952f7e9cb62 Mon Sep 17 00:00:00 2001 From: Joel <30326841+McDude73@users.noreply.github.com> Date: Wed, 17 Jun 2020 16:56:26 -0600 Subject: [PATCH 3/8] New Sorts Added 4 new sorts (Inverse Grate, Reverse Grate, Bozo, Modulo) --- src/sorts/BozoSort.java | 48 ++++++++++++++++++++++++ src/sorts/InverseGrateSort.java | 59 ++++++++++++++++++++++++++++++ src/sorts/ModuloSort.java | 65 +++++++++++++++++++++++++++++++++ src/sorts/ReverseGrateSort.java | 59 ++++++++++++++++++++++++++++++ 4 files changed, 231 insertions(+) create mode 100644 src/sorts/BozoSort.java create mode 100644 src/sorts/InverseGrateSort.java create mode 100644 src/sorts/ModuloSort.java create mode 100644 src/sorts/ReverseGrateSort.java diff --git a/src/sorts/BozoSort.java b/src/sorts/BozoSort.java new file mode 100644 index 00000000..b59f9828 --- /dev/null +++ b/src/sorts/BozoSort.java @@ -0,0 +1,48 @@ +package sorts; + +import templates.BogoSorting; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Bozosort will check to see if all the elements are sorted in their correct + * positions, just like Bogosort. + * + * If there is an element out of place, Bozosort will swap two elements at random + * instead of swapping every single one of them. + * + * >> Imported by Joel "McDude_73" Zaleschuk + */ + +final public class BozoSort extends BogoSorting { + public BozoSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Bozo"); + this.setRunAllID("Bozo Sort"); + this.setReportSortID("Bozosort"); + this.setCategory("Distributive Sorts"); + this.isComparisonBased(false); //Comparisons are not used to swap elements + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(true); + this.setUnreasonableLimit(16); + this.isBogoSort(true); + } + + @Override + public void runSort(int[] array, int currentLen, int bucketCount) { + while(!this.bogoIsSorted(array, currentLen)) { + int a = (int) (Math.random() * currentLen); + int b = (int) (Math.random() * currentLen); + + if(a == b) { + if(b + 1 >= currentLen) b = 0; + else ++b; + } + Writes.swap(array, a, b, 0, true, false); + } + } +} \ No newline at end of file diff --git a/src/sorts/InverseGrateSort.java b/src/sorts/InverseGrateSort.java new file mode 100644 index 00000000..6704cd0e --- /dev/null +++ b/src/sorts/InverseGrateSort.java @@ -0,0 +1,59 @@ +package sorts; + +import templates.Sort; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Grate Sort will commit a pass every time the array is not considered sorted. + * What it will do is it will start by comparing the element selected from the pass to the + * right-most element. + * + * It will swap the elements if the right-most element is smaller than the one on the pass. + * It will check the element one to the left from where the last element was checked until + * the right marker reaches the element being checked during the pass. + * + * If at any point a swap was made, another pass must take place after the current one. + * + * >> Idea from EilrahcF#1021 + * >> Scripted by Joel "McDude_73" Zaleschuk + */ + +final public class InverseGrateSort extends Sort { + public InverseGrateSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Inverse Grate"); + this.setRunAllID("Inverse Grate Sort"); + this.setReportSortID("Inverse Grate Sort"); + this.setCategory("Exchange Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(true); + this.setUnreasonableLimit(512); + this.isBogoSort(false); + } + + @Override + public void runSort(int[] array, int currentLength, int bucketCount) { + boolean sorted = false; + while(!sorted) { + sorted = true; + for(int i=currentLength-1;i>0;i--) { + for(int j=0;j aux = new ArrayList<>(); + + while(modulo <= len) { + aux.clear(); + for(int init=0;init= len) { + j++; + i = -1; + } + } + if(modulo * 2 >= len && askAgain) { + askAgain = false; + modulo = len; + } else { + modulo *= 2; + } + } + } + + @Override + public void runSort(int[] array, int length, int bucketCount) { + if(bucketCount <= 1) bucketCount = 8; + if(bucketCount >= length) bucketCount = length; + moduloSort(array, length, bucketCount, bucketCount == length ? false : true); + } +} \ No newline at end of file diff --git a/src/sorts/ReverseGrateSort.java b/src/sorts/ReverseGrateSort.java new file mode 100644 index 00000000..3f1a61a4 --- /dev/null +++ b/src/sorts/ReverseGrateSort.java @@ -0,0 +1,59 @@ +package sorts; + +import templates.Sort; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Grate Sort will commit a pass every time the array is not considered sorted. + * What it will do is it will start by comparing the element selected from the pass to the + * right-most element. + * + * It will swap the elements if the left-most element is smaller than the one on the pass. + * It will check the element one to the right from where the last element was checked until + * the right marker reaches the element being checked during the pass. + * + * If at any point a swap was made, another pass must take place after the current one. + * + * >> Idea from EilrahcF#1021 + * >> Scripted by Joel "McDude_73" Zaleschuk + */ + +final public class ReverseGrateSort extends Sort { + public ReverseGrateSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Reverse Grate"); + this.setRunAllID("Reverse Grate Sort"); + this.setReportSortID("Reverse Grate Sort"); + this.setCategory("Exchange Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(true); + this.setUnreasonableLimit(512); + this.isBogoSort(false); + } + + @Override + public void runSort(int[] array, int currentLength, int bucketCount) { + boolean sorted = false; + while(!sorted) { + sorted = true; + for(int i=0;i 0) { + sorted = false; + Writes.swap(array, i, j, 0.1, true, false); + break; + } + } + } + } + } +} \ No newline at end of file From af8e71770d09ed2305cf68eab8cafd9d026be34f Mon Sep 17 00:00:00 2001 From: Joel <30326841+McDude73@users.noreply.github.com> Date: Wed, 17 Jun 2020 20:47:11 -0600 Subject: [PATCH 4/8] Description Fixes Fixed the descriptions for some of the newly created sorts. --- src/sorts/InverseGrateSort.java | 10 +--------- src/sorts/ModuloSort.java | 31 +++++++++++++++++-------------- src/sorts/ReverseGrateSort.java | 10 +--------- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/sorts/InverseGrateSort.java b/src/sorts/InverseGrateSort.java index 6704cd0e..856abf3b 100644 --- a/src/sorts/InverseGrateSort.java +++ b/src/sorts/InverseGrateSort.java @@ -7,15 +7,7 @@ import utils.Writes; /* - * Grate Sort will commit a pass every time the array is not considered sorted. - * What it will do is it will start by comparing the element selected from the pass to the - * right-most element. - * - * It will swap the elements if the right-most element is smaller than the one on the pass. - * It will check the element one to the left from where the last element was checked until - * the right marker reaches the element being checked during the pass. - * - * If at any point a swap was made, another pass must take place after the current one. + * Inverse Grate Sort * * >> Idea from EilrahcF#1021 * >> Scripted by Joel "McDude_73" Zaleschuk diff --git a/src/sorts/ModuloSort.java b/src/sorts/ModuloSort.java index 46751917..9cf22de2 100644 --- a/src/sorts/ModuloSort.java +++ b/src/sorts/ModuloSort.java @@ -1,7 +1,5 @@ package sorts; -import java.util.ArrayList; - import templates.Sort; import utils.Delays; import utils.Highlights; @@ -9,6 +7,16 @@ import utils.Writes; /* + * Modulo Sort takes in a base number, and uses it as a modulo divisor. + * + * This sort writes every element of the array into a separate one, and then applies a modulo + * operation, which is how many buckets will be created (Base 8 would mean 8 buckets.), and + * puts the elements in there based on their modulo result. + * + * This process is repeated by doubling the modulo until it is greater than or equal to the length of + * the initial array, then it will commit one last pass to sort the remaining elements. + * + * >> Scripted by Joel "McDude_73" Zaleschuk */ final public class ModuloSort extends Sort { @@ -22,25 +30,20 @@ public ModuloSort(Delays delayOps, Highlights markOps, Reads readOps, Writes wri this.isComparisonBased(false); this.isBucketSort(true); this.isRadixSort(true); - this.isUnreasonablySlow(true); - this.setUnreasonableLimit(8192); + this.isUnreasonablySlow(false); + this.setUnreasonableLimit(0); this.isBogoSort(false); } private void moduloSort(int[] array, int len, int modulo, boolean askAgain) { - ArrayList aux = new ArrayList<>(); - + int[] aux = new int[len]; while(modulo <= len) { - aux.clear(); for(int init=0;init= len) { j++; @@ -58,7 +61,7 @@ private void moduloSort(int[] array, int len, int modulo, boolean askAgain) { @Override public void runSort(int[] array, int length, int bucketCount) { - if(bucketCount <= 1) bucketCount = 8; + if(bucketCount <= 1) bucketCount = 4; if(bucketCount >= length) bucketCount = length; moduloSort(array, length, bucketCount, bucketCount == length ? false : true); } diff --git a/src/sorts/ReverseGrateSort.java b/src/sorts/ReverseGrateSort.java index 3f1a61a4..6b3e9a22 100644 --- a/src/sorts/ReverseGrateSort.java +++ b/src/sorts/ReverseGrateSort.java @@ -7,15 +7,7 @@ import utils.Writes; /* - * Grate Sort will commit a pass every time the array is not considered sorted. - * What it will do is it will start by comparing the element selected from the pass to the - * right-most element. - * - * It will swap the elements if the left-most element is smaller than the one on the pass. - * It will check the element one to the right from where the last element was checked until - * the right marker reaches the element being checked during the pass. - * - * If at any point a swap was made, another pass must take place after the current one. + * Reverse Grate Sort * * >> Idea from EilrahcF#1021 * >> Scripted by Joel "McDude_73" Zaleschuk From 136536d7a87a1a0b3f6e451f5277c939653ad3a6 Mon Sep 17 00:00:00 2001 From: Joel <30326841+McDude73@users.noreply.github.com> Date: Sun, 21 Jun 2020 19:40:33 -0600 Subject: [PATCH 5/8] Changed to Support Run All Changed Iterative Merge and Quick to support the Run All Sorts option. --- src/sorts/IterativeMergeSort.java | 12 ++++++------ src/sorts/IterativeQuickSort.java | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sorts/IterativeMergeSort.java b/src/sorts/IterativeMergeSort.java index 7941814d..1d694c3e 100644 --- a/src/sorts/IterativeMergeSort.java +++ b/src/sorts/IterativeMergeSort.java @@ -49,11 +49,11 @@ private void merge(int[] array, int left, int middle, int right) { for(i=0;i Date: Sun, 21 Jun 2020 19:43:03 -0600 Subject: [PATCH 6/8] Added Custom Sorts to Run All Sorts --- src/threads/RunExchangeSorts.java | 10 +++++++++- src/threads/RunHybridSorts.java | 6 +++++- src/threads/RunImpracticalSorts.java | 14 +++++++++++++- src/threads/RunSelectionSorts.java | 6 +++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/threads/RunExchangeSorts.java b/src/threads/RunExchangeSorts.java index 5926f30c..a6794b7e 100644 --- a/src/threads/RunExchangeSorts.java +++ b/src/threads/RunExchangeSorts.java @@ -8,9 +8,11 @@ import sorts.CombSort; import sorts.DualPivotQuickSort; import sorts.GnomeSort; +import sorts.IterativeQuickSort; import sorts.LLQuickSort; import sorts.LRQuickSort; import sorts.OddEvenSort; +import sorts.SlopeSort; import sorts.SmartBubbleSort; import sorts.SmartCocktailSort; import sorts.SmartGnomeSort; @@ -55,16 +57,18 @@ final public class RunExchangeSorts extends MultipleSortThread { private Sort GnomeSort; private Sort SmartGnomeSort; private Sort BinaryGnomeSort; + private Sort SlopeSort; private Sort CombSort; private Sort CircleSort; private Sort LLQuickSort; private Sort LRQuickSort; private Sort DualPivotQuickSort; private Sort StableQuickSort; + private Sort IterativeQuickSort; public RunExchangeSorts(ArrayVisualizer ArrayVisualizer) { super(ArrayVisualizer); - this.sortCount = 14; + this.sortCount = 16; this.categoryCount = this.sortCount; BubbleSort = new BubbleSort(Delays, Highlights, Reads, Writes); @@ -75,12 +79,14 @@ public RunExchangeSorts(ArrayVisualizer ArrayVisualizer) { GnomeSort = new GnomeSort(Delays, Highlights, Reads, Writes); SmartGnomeSort = new SmartGnomeSort(Delays, Highlights, Reads, Writes); BinaryGnomeSort = new BinaryGnomeSort(Delays, Highlights, Reads, Writes); + SlopeSort = new SlopeSort(Delays, Highlights, Reads, Writes); CombSort = new CombSort(Delays, Highlights, Reads, Writes); CircleSort = new CircleSort(Delays, Highlights, Reads, Writes); LLQuickSort = new LLQuickSort(Delays, Highlights, Reads, Writes); LRQuickSort = new LRQuickSort(Delays, Highlights, Reads, Writes); DualPivotQuickSort = new DualPivotQuickSort(Delays, Highlights, Reads, Writes); StableQuickSort = new StableQuickSort(Delays, Highlights, Reads, Writes); + IterativeQuickSort = new IterativeQuickSort(Delays, Highlights, Reads, Writes); } @Override @@ -93,12 +99,14 @@ protected synchronized void executeSortList(int[] array) throws Exception { RunExchangeSorts.this.runIndividualSort(GnomeSort, 0, array, 128, 0.025); RunExchangeSorts.this.runIndividualSort(SmartGnomeSort, 0, array, 128, 0.025); RunExchangeSorts.this.runIndividualSort(BinaryGnomeSort, 0, array, 128, 0.025); + RunExchangeSorts.this.runIndividualSort(SlopeSort, 0, array, 128, 0.025); RunExchangeSorts.this.runIndividualSort(CombSort, 0, array, 1024, 1); RunExchangeSorts.this.runIndividualSort(CircleSort, 0, array, 1024, 1); RunExchangeSorts.this.runIndividualSort(LLQuickSort, 0, array, 2048, ArrayManager.getShuffle() == Shuffles.RANDOM ? 1.5 : 65); RunExchangeSorts.this.runIndividualSort(LRQuickSort, 0, array, 2048, 1); RunExchangeSorts.this.runIndividualSort(DualPivotQuickSort, 0, array, 2048, ArrayManager.getShuffle() == Shuffles.RANDOM ? 1 : 50); RunExchangeSorts.this.runIndividualSort(StableQuickSort, 0, array, 2048, ArrayManager.getShuffle() == Shuffles.RANDOM ? 1 : 50); + RunExchangeSorts.this.runIndividualSort(IterativeQuickSort, 0, array, 2048, ArrayManager.getShuffle() == Shuffles.RANDOM ? 1 : 50); } @Override diff --git a/src/threads/RunHybridSorts.java b/src/threads/RunHybridSorts.java index 3ca2a196..708597da 100644 --- a/src/threads/RunHybridSorts.java +++ b/src/threads/RunHybridSorts.java @@ -11,6 +11,7 @@ import sorts.IntroCircleSort; import sorts.IntroSort; import sorts.OptimizedDualPivotQuickSort; +import sorts.SlideSort; import sorts.SqrtSort; import sorts.TimSort; import sorts.WeaveMergeSort; @@ -61,10 +62,11 @@ final public class RunHybridSorts extends MultipleSortThread { private Sort OptimizedDualPivotQuickSort; private Sort BranchedPDQSort; private Sort BranchlessPDQSort; + private Sort SlideSort; public RunHybridSorts(ArrayVisualizer ArrayVisualizer) { super(ArrayVisualizer); - this.sortCount = 14; + this.sortCount = 15; this.categoryCount = this.sortCount; HybridCombSort = new HybridCombSort(Delays, Highlights, Reads, Writes); @@ -81,6 +83,7 @@ public RunHybridSorts(ArrayVisualizer ArrayVisualizer) { OptimizedDualPivotQuickSort = new OptimizedDualPivotQuickSort(Delays, Highlights, Reads, Writes); BranchedPDQSort = new BranchedPDQSort(Delays, Highlights, Reads, Writes); BranchlessPDQSort = new BranchlessPDQSort(Delays, Highlights, Reads, Writes); + SlideSort = new SlideSort(Delays, Highlights, Reads, Writes); } @Override @@ -99,6 +102,7 @@ protected synchronized void executeSortList(int[] array) throws Exception { RunHybridSorts.this.runIndividualSort(OptimizedDualPivotQuickSort, 0, array, 2048, 0.75); RunHybridSorts.this.runIndividualSort(BranchedPDQSort, 0, array, 2048, 0.75); RunHybridSorts.this.runIndividualSort(BranchlessPDQSort, 0, array, 2048, 0.75); + RunHybridSorts.this.runIndividualSort(SlideSort, 0, array, 1024, 0.5); } @Override diff --git a/src/threads/RunImpracticalSorts.java b/src/threads/RunImpracticalSorts.java index 69da1159..10d39518 100644 --- a/src/threads/RunImpracticalSorts.java +++ b/src/threads/RunImpracticalSorts.java @@ -3,10 +3,13 @@ import main.ArrayVisualizer; import sorts.BadSort; import sorts.BogoSort; +import sorts.BozoSort; import sorts.BubbleBogoSort; import sorts.CocktailBogoSort; import sorts.ExchangeBogoSort; +import sorts.GrateSort; import sorts.LessBogoSort; +import sorts.ReverseGrateSort; import sorts.SillySort; import sorts.SlowSort; import sorts.StoogeSort; @@ -43,27 +46,33 @@ of this software and associated documentation files (the "Software"), to deal final public class RunImpracticalSorts extends MultipleSortThread { private Sort BadSort; private Sort StoogeSort; + private Sort GrateSort; + private Sort ReverseGrateSort; private Sort SillySort; private Sort SlowSort; private Sort ExchangeBogoSort; private Sort BubbleBogoSort; private Sort LessBogoSort; private Sort CocktailBogoSort; + private Sort BozoSort; private Sort BogoSort; public RunImpracticalSorts(ArrayVisualizer ArrayVisualizer) { super(ArrayVisualizer); - this.sortCount = 9; + this.sortCount = 12; this.categoryCount = this.sortCount; BadSort = new BadSort(Delays, Highlights, Reads, Writes); StoogeSort = new StoogeSort(Delays, Highlights, Reads, Writes); + GrateSort = new GrateSort(Delays, Highlights, Reads, Writes); + ReverseGrateSort = new ReverseGrateSort(Delays, Highlights, Reads, Writes); SillySort = new SillySort(Delays, Highlights, Reads, Writes); SlowSort = new SlowSort(Delays, Highlights, Reads, Writes); ExchangeBogoSort = new ExchangeBogoSort(Delays, Highlights, Reads, Writes); BubbleBogoSort = new BubbleBogoSort(Delays, Highlights, Reads, Writes); LessBogoSort = new LessBogoSort(Delays, Highlights, Reads, Writes); CocktailBogoSort = new CocktailBogoSort(Delays, Highlights, Reads, Writes); + BozoSort = new BozoSort(Delays, Highlights, Reads, Writes); BogoSort = new BogoSort(Delays, Highlights, Reads, Writes); } @@ -71,6 +80,8 @@ public RunImpracticalSorts(ArrayVisualizer ArrayVisualizer) { protected synchronized void executeSortList(int[] array) throws Exception { RunImpracticalSorts.this.runIndividualSort(BadSort, 0, array, 64, 0.0075); RunImpracticalSorts.this.runIndividualSort(StoogeSort, 0, array, 64, 0.005); + RunImpracticalSorts.this.runIndividualSort(GrateSort, 0, array, 32, 0.1); + RunImpracticalSorts.this.runIndividualSort(ReverseGrateSort, 0, array, 32, 0.025); RunImpracticalSorts.this.runIndividualSort(SillySort, 0, array, 64, 10); RunImpracticalSorts.this.runIndividualSort(SlowSort, 0, array, 64, 10); Sounds.toggleSofterSounds(true); @@ -78,6 +89,7 @@ protected synchronized void executeSortList(int[] array) throws Exception { RunImpracticalSorts.this.runIndividualSort(BubbleBogoSort, 0, array, 32, 0.01); RunImpracticalSorts.this.runIndividualSort(LessBogoSort, 0, array, 16, 0.0025); RunImpracticalSorts.this.runIndividualSort(CocktailBogoSort, 0, array, 16, 0.0025); + RunImpracticalSorts.this.runIndividualSort(BozoSort, 0, array, 8, 1); RunImpracticalSorts.this.runIndividualSort(BogoSort, 0, array, 8, 1); Sounds.toggleSofterSounds(false); } diff --git a/src/threads/RunSelectionSorts.java b/src/threads/RunSelectionSorts.java index 16b76546..127f1f0a 100644 --- a/src/threads/RunSelectionSorts.java +++ b/src/threads/RunSelectionSorts.java @@ -1,6 +1,7 @@ package threads; import main.ArrayVisualizer; +import sorts.BingoSort; import sorts.CycleSort; import sorts.DoubleSelectionSort; import sorts.FlippedMinHeapSort; @@ -45,6 +46,7 @@ of this software and associated documentation files (the "Software"), to deal final public class RunSelectionSorts extends MultipleSortThread { private Sort SelectionSort; private Sort DoubleSelectionSort; + private Sort BingoSort; private Sort CycleSort; private Sort MaxHeapSort; private Sort MinHeapSort; @@ -57,11 +59,12 @@ final public class RunSelectionSorts extends MultipleSortThread { public RunSelectionSorts(ArrayVisualizer ArrayVisualizer) { super(ArrayVisualizer); - this.sortCount = 11; + this.sortCount = 12; this.categoryCount = this.sortCount; SelectionSort = new SelectionSort(Delays, Highlights, Reads, Writes); DoubleSelectionSort = new DoubleSelectionSort(Delays, Highlights, Reads, Writes); + BingoSort = new BingoSort(Delays, Highlights, Reads, Writes); CycleSort = new CycleSort(Delays, Highlights, Reads, Writes); MaxHeapSort = new MaxHeapSort(Delays, Highlights, Reads, Writes); MinHeapSort = new MinHeapSort(Delays, Highlights, Reads, Writes); @@ -77,6 +80,7 @@ public RunSelectionSorts(ArrayVisualizer ArrayVisualizer) { protected synchronized void executeSortList(int[] array) throws Exception { RunSelectionSorts.this.runIndividualSort(SelectionSort, 0, array, 128, 0.01); RunSelectionSorts.this.runIndividualSort(DoubleSelectionSort, 0, array, 128, 0.01); + RunSelectionSorts.this.runIndividualSort(BingoSort, 0, array, 128, 0.01); RunSelectionSorts.this.runIndividualSort(CycleSort, 0, array, 128, 0.01); RunSelectionSorts.this.runIndividualSort(MaxHeapSort, 0, array, 2048, 1.5); RunSelectionSorts.this.runIndividualSort(MinHeapSort, 0, array, 2048, 1.5); From 872f6a4bcb61b88163b20622f40dbda5e729cbe2 Mon Sep 17 00:00:00 2001 From: Joel <30326841+McDude73@users.noreply.github.com> Date: Sun, 21 Jun 2020 19:45:26 -0600 Subject: [PATCH 7/8] Removed Inverse Grate Sort --- src/sorts/InverseGrateSort.java | 51 --------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/sorts/InverseGrateSort.java diff --git a/src/sorts/InverseGrateSort.java b/src/sorts/InverseGrateSort.java deleted file mode 100644 index 856abf3b..00000000 --- a/src/sorts/InverseGrateSort.java +++ /dev/null @@ -1,51 +0,0 @@ -package sorts; - -import templates.Sort; -import utils.Delays; -import utils.Highlights; -import utils.Reads; -import utils.Writes; - -/* - * Inverse Grate Sort - * - * >> Idea from EilrahcF#1021 - * >> Scripted by Joel "McDude_73" Zaleschuk - */ - -final public class InverseGrateSort extends Sort { - public InverseGrateSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { - super(delayOps, markOps, readOps, writeOps); - - this.setSortPromptID("Inverse Grate"); - this.setRunAllID("Inverse Grate Sort"); - this.setReportSortID("Inverse Grate Sort"); - this.setCategory("Exchange Sorts"); - this.isComparisonBased(true); - this.isBucketSort(false); - this.isRadixSort(false); - this.isUnreasonablySlow(true); - this.setUnreasonableLimit(512); - this.isBogoSort(false); - } - - @Override - public void runSort(int[] array, int currentLength, int bucketCount) { - boolean sorted = false; - while(!sorted) { - sorted = true; - for(int i=currentLength-1;i>0;i--) { - for(int j=0;j Date: Sun, 21 Jun 2020 19:49:51 -0600 Subject: [PATCH 8/8] Forgot Slope Sort Slope Sort was used in the Run All Exchange Sorts file, so this was fixed. --- src/sorts/SlopeSort.java | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/sorts/SlopeSort.java diff --git a/src/sorts/SlopeSort.java b/src/sorts/SlopeSort.java new file mode 100644 index 00000000..293f50a3 --- /dev/null +++ b/src/sorts/SlopeSort.java @@ -0,0 +1,51 @@ +package sorts; + +import templates.Sort; +import utils.Delays; +import utils.Highlights; +import utils.Reads; +import utils.Writes; + +/* + * Slope Sort has a similar objective to Gnome Sort. + * + * If any element is not in the correct position, it will swap the element to its + * correct position like normal, however the extra behavior that comes in from + * Gnome Sort will also check to see if the elements beyond the one that was + * swapped are in order as well. + * + * >> Idea from EilrahcF#1021 + * >> Scripted by Joel "McDude_73" Zaleschuk + */ + +final public class SlopeSort extends Sort { + public SlopeSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { + super(delayOps, markOps, readOps, writeOps); + + this.setSortPromptID("Slope"); + this.setRunAllID("Slope Sort"); + this.setReportSortID("Slopesort"); + this.setCategory("Exchange Sorts"); + this.isComparisonBased(true); + this.isBucketSort(false); + this.isRadixSort(false); + this.isUnreasonablySlow(false); + this.setUnreasonableLimit(0); + this.isBogoSort(false); + } + + @Override + public void runSort(int[] array, int length, int bucketCount) { + for(int i=1,j=1;i=0;k--,i--) { + Highlights.markArray(1, i); + Highlights.markArray(2, k); + Delays.sleep(0.05); + if(Reads.compare(array[i], array[k]) < 0) { + Writes.swap(array, i, k, 0.02, true, false); + } + } + i = j; + } + } +} \ No newline at end of file