我是靠谱客的博主 冷酷铃铛,这篇文章主要介绍JavaScript实现快排,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
Array.prototype.quickSort = function() { const l = this.length if(l < 2) return this const basic = this[0], left = [], right = [] for(let i = 1; i < l; i++) { const iv = this[i] iv >= basic && right.push(iv) // to avoid repeatly element. iv < basic && left.push(iv) } return left.quickSort().concat(basic, right.quickSort()) } const arr = [5, 3, 7, 4, 1, 9, 8, 6, 2]; const ascendArr = arr.quickSort()
复制代码
1
2
3
总结: 1、wikipedia大法好。这上面资料的质量很好 2、算法完全可以用适当的空间换取代码清晰

 

最后

以上就是冷酷铃铛最近收集整理的关于JavaScript实现快排的全部内容,更多相关JavaScript实现快排内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部