mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
merge: Add Description and Optamization (#852)
This commit is contained in:
@ -1,9 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy.
|
* @function QuickSort
|
||||||
*
|
* @description Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy.
|
||||||
* For more information see here: https://en.wikipedia.org/wiki/Quicksort
|
* @param {Integer[]} items - Array of integers
|
||||||
*/
|
* @return {Integer[]} - Sorted array.
|
||||||
export function quickSort (items) {
|
* @see [QuickSort](https://en.wikipedia.org/wiki/Quicksort)
|
||||||
|
*/
|
||||||
|
function quickSort (items) {
|
||||||
const length = items.length
|
const length = items.length
|
||||||
|
|
||||||
if (length <= 1) {
|
if (length <= 1) {
|
||||||
@ -21,9 +23,8 @@ export function quickSort (items) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sorted = quickSort(LESSER)
|
const sorted = [...quickSort(LESSER), PIVOT, ...quickSort(GREATER)]
|
||||||
sorted.push(PIVOT)
|
|
||||||
sorted = sorted.concat(quickSort(GREATER))
|
|
||||||
|
|
||||||
return sorted
|
return sorted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { quickSort }
|
||||||
|
Reference in New Issue
Block a user