![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
javascript
有菜又爱玩
这个作者很懒,什么都没留下…
展开
-
javaScript二分法查找
var array = [1, 2, 3, 4, 5, 6];function search(array, target) { let left = 0; let right = array.length - 1; let middle; while (left <= right) { // Math.floor向下取整 middle = Math.floor(left + (right - left) / 2); // 防止栈溢出 if (array[mi.原创 2021-07-14 10:46:07 · 106 阅读 · 0 评论 -
JavaScript选择排序
function selectionSort(arr) { function exchange(v1, v2) { let temp = arr[v1] arr[v1] = arr[v2] arr[v2] = temp } let length = arr.length for(let i = 0; i < length - 1; i++) { let min = i //获取遍历的每一项索引.原创 2021-06-05 11:53:34 · 92 阅读 · 1 评论 -
JavaScript冒泡排序
function bubbleSort(arr) { // 两个数据进行交换 function exchange(v1, v2) { let temp = arr[v1] arr[v1] = arr[v2] arr[v2] = temp } // 数组长度 let length = arr.length for (let i = length - 1; i >= 0; ...原创 2021-06-04 11:40:31 · 83 阅读 · 1 评论