Class BubbleSortStrategy
java.lang.Object
com.github.rlacher.sortbench.strategies.implementations.BubbleSortStrategy
- All Implemented Interfaces:
SortStrategy
Implements the bubble sort algorithm as a sorting strategy.
This class implements the SortStrategy interface and provides a method
to perform bubble sort on an array of integers.
-
Constructor Summary
ConstructorsConstructorDescriptionBubbleSortStrategy(Benchmarker benchmarker) Constructor for theBubbleSortStrategyclass. -
Method Summary
Modifier and TypeMethodDescriptionsort(int[] array) Sorts the provided array in ascending order using the bubble 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
-
BubbleSortStrategy
Constructor for theBubbleSortStrategyclass.- 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 bubble sort algorithm.Summary of bubble sort algorithm: Bubble sort repeatedly compares adjacent elements, swapping them if they are out of order. The process continues until no swaps are needed in a complete pass, indicating a sorted array.
Input array validation is assumed to be performed by the calling
Sorterclass.- Specified by:
sortin interfaceSortStrategy- Parameters:
array- The array to be sorted.- Returns:
- The sorted array.
-