Class QuickSortStrategy
java.lang.Object
com.github.rlacher.sortbench.strategies.implementations.QuickSortStrategy
- All Implemented Interfaces:
SortStrategy
Implements the quick sort algorithm as a sorting strategy.
This class implements the SortStrategy interface and provides a method
to perform quick sort on an array of integers.
-
Constructor Summary
ConstructorsConstructorDescriptionQuickSortStrategy(Benchmarker benchmarker) Constructor for theQuickSortStrategyclass. -
Method Summary
Modifier and TypeMethodDescriptionsort(int[] array) Sorts the provided array in ascending order using the quick sort algorithm.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.github.rlacher.sortbench.strategies.SortStrategy
name, swap
-
Constructor Details
-
QuickSortStrategy
Constructor for theQuickSortStrategyclass.- Parameters:
benchmarker- The benchmarker to be used for profiling.- Throws:
IllegalArgumentException- If the benchmarker isnull.
-
-
Method Details
-
sort
Sorts the provided array in ascending order using the quick sort algorithm.Summary of quick sort algorithm: Quicksort, using the first element as the pivot, partitions the array such that elements smaller than the pivot are on the left and equal or larger elements are on the right. The pivot is then swapped to its correct sorted position between these partitions. The algorithm recursively sorts the left and right subarrays until they contain zero or one element.
Input array validation is assumed to be performed by the calling
Sorterclass.- Specified by:
sortin interfaceSortStrategy- Parameters:
array- The array to be sorted.- Returns:
- A
BenchmarkMetriccontaining performance information about the sorting process. - Throws:
NullPointerException- If array isnull(though this should be prevented by the caller).
-