param { number [ ] } array return { number [ ] } function QuickSort ( array ) { if ( array . length < 2 ) { return array ; } let target = array [ 0 ] ; let left = [ ] ; let right = [ ] ; for ( let i = 1 ; i < array . length ; i ++ ) { if ( array [ i ] < target ) { left . push ( array [ i ] ) ; } else { right . push ( array [ i ] ) ; } } return QuickSort ( left ) . concat ( [ target ] , QuickSort ( right ) ) ; } param { number [ ] } array param { number } start param { number } end return { number [ ] | null } function QuickSort2 ( array , start , end ) { if ( end - start < 1 ) { return null ; } const target = array [ start ] ; let l = start ; let r = end ; while ( l < r ) { while ( l < r && array [ r ] >= target ) { r -- ; } if ( l < r ) { array [ l ++ ] = array [ r ] ; } while ( l < r && array [ l ] < target ) { l ++ ; } if ( l < r ) { array [ r -- ] = array [ l ] ; } } array [ l ] = target ; QuickSort2 ( array , start , l - 1 ) ; QuickSort2 ( array , l + 1 , end ) ; return array ; } export { QuickSort , QuickSort2 } ;