From bd8075e54cb5d6b8229a29d22a00751d4f793855 Mon Sep 17 00:00:00 2001 From: wakfi <55608093+wakfi@users.noreply.github.com> Date: Mon, 7 Sep 2020 15:06:47 -0700 Subject: [PATCH] Change max from parameter to variable --- src/sorts/SmartBogoSort.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/sorts/SmartBogoSort.java b/src/sorts/SmartBogoSort.java index 1b400d69..c2cca708 100644 --- a/src/sorts/SmartBogoSort.java +++ b/src/sorts/SmartBogoSort.java @@ -27,7 +27,7 @@ of this software and associated documentation files (the "Software"), to deal final public class SmartBogoSort extends BogoSorting { - private int length; + private int max; public SmartBogoSort(Delays delayOps, Highlights markOps, Reads readOps, Writes writeOps) { super(delayOps, markOps, readOps, writeOps); @@ -45,24 +45,23 @@ public SmartBogoSort(Delays delayOps, Highlights markOps, Reads readOps, Writes @Override public void runSort(int[] array, int currentLen, int bucketCount) { - length = currentLen; - permutationSort(array, 0, currentLen-1); + max = currentLen - 1; + permutationSort(array, 0); } - private boolean permutationSort(int[] array, int min, int max) + private boolean permutationSort(int[] array, int min) { - if(max != length-1) throw new RuntimeException(); boolean sorted = false; int i; for(i = max; i > min; i--) { if(max > min+1) { - sorted = permutationSort(array, min+1, max); //permutation = recurrence relation + sorted = permutationSort(array, min+1); //permutation = recurrence relation } if(sorted || this.bogoIsSorted(array, max+1)) { - return sorted; + return true; } if((max+1-min)%2 == 0) { @@ -73,7 +72,7 @@ private boolean permutationSort(int[] array, int min, int max) } if(max > min+1) { - return permutationSort(array, min+1, max); //permutation = recurrence relation + return permutationSort(array, min+1); //permutation = recurrence relation } return false; }