Skip to content

@ryanuo/utils / algorithm / bubbleSort

Function: bubbleSort() ​

ts
function bubbleSort(arr): number[];

冒泡排序(Bubble Sort)

Parameters ​

arr ​

number[]

数组

Returns ​

number[]

排序后的数组

Example ​

ts
import { 
bubbleSort
} from '@ryanuo/utils'
const
sorted
=
bubbleSort
([5, 3, 8, 4, 2])
console
.
log
(
sorted
) // [2, 3, 4, 5, 8]