8 种排序算法的代码实现
找工作之际,重新学习了常见的排序算法,像看似无害的冒泡排序其实也有很多种优化方案,还有简单粗暴的选择排序,模拟抓牌的插入排序,弥补插入排序缺陷的希尔排序,使用了分治思想的归并排序,有点难搞的快速排序,模拟树状结构的堆排序,以及不按套路出牌的基数排序等。 冒泡排序常规冒泡排序1234567891011function bubbleSort(arr) { if (!Array.isArray(arr) || arr.length <= 1) return; for (let i = 0; i < arr.length - 1; i++) { for (let j = 0; j < arr.length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; } } } return...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment