Default comparator function used for sorting
first element to compare
second element to compare
a negative number if a < b, 0 if a = b, a positive number if a > b
Private Readonly defaultPrivate Readonly sizePrivate Readonly valuesStatic defaultStatic sortSorts the array using the BubbleSort algorithm. Static method, no need to instantiate class
the array to be sorted
the comparator function used for sorting, defaults to numerical comparison
Default comparator function used for sorting
first element to compare
second element to compare
a negative number if a < b, 0 if a = b, a positive number if a > b
a new array with the elements sorted
Generated using TypeDoc
BubbleSort is a simple sorting algorithm that repeatedly steps through the array, compares adjacent elements and swaps them if they are in the wrong order. The pass through the array is repeated until the array is sorted.
The algorithm gets its name from the way smaller elements "bubble" to the top of the array. Although simple, it is not efficient for large datasets as it has a time complexity of O(n^2) in both the average and worst case scenarios.
The best-case time complexity is O(n) when the array is already sorted.
Example
Example