Skip to content

Commit 6f827b7

Browse files
committed
Fixed Quicksort printUpdates
If 'printUpdates' is set to false, Quicksort no longer prints any updates while sorting.
1 parent d9c3374 commit 6f827b7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compare-sorting-algorithms.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void Main(string[] args)
4444
string orderOfArray = r; // a/d/r
4545
ulong numberOfSorts = 1;
4646
int lengthOfArray = 10;
47-
bool printUpdates = true;
47+
bool printUpdates = false;
4848

4949
Console.WriteLine("Sorting algorithm: {0}\nResults of {1} passes of {2}-int {3} arrays:\n",
5050
sortingAlgorithm, numberOfSorts, lengthOfArray, orderOfArray);
@@ -447,8 +447,11 @@ private static int Partition(int[] array, int start, int end, bool printUpdates)
447447
totalComparisonsQuick += comparisons;
448448
totalSwapsQuick += swaps;
449449

450-
string message = "Pivot was " + pivot.ToString().PadLeft(2) + ", moved to index " + partitionIndex.ToString().PadLeft(2);
451-
PrintArray(array, message);
450+
if (printUpdates)
451+
{
452+
string message = "Pivot was " + pivot.ToString().PadLeft(2) + ", moved to index " + partitionIndex.ToString().PadLeft(2);
453+
PrintArray(array, message);
454+
}
452455
return partitionIndex;
453456
}
454457

0 commit comments

Comments
 (0)