ts-ds / bubbleSort
Function: bubbleSort()
ts
function bubbleSort<T>(array, compareFn?): void;Defined in: sort/bubble/bubble.ts:18
Sorts an array in place using bubble sort.
Repeatedly walks through the array and swaps adjacent elements that are in the wrong order. After pass k the k largest elements are in their final places. Stops early when a pass makes no swaps.
| Time: best | Time: average | Time: worst | Memory | Stable | In place |
|---|---|---|---|---|---|
| O(n) | O(n²) | O(n²) | O(1) | yes | yes |
Type Parameters
| Type Parameter | Description |
|---|---|
T |
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
array | T[] | undefined | Array to sort. It is modified. |
compareFn? | CompareFn<T> | defaultCompare | Order of elements, ascending by default. |
Returns
void
Nothing — array itself is sorted.