1.找出最大和第二大元素一定需要进行几次比较,在一个有8个int数据的数组中( )
2.贪心算法
3.js链表:单向链表与双向链表
具体见链接:https://segmentfault.com/a/1190000017569816
4.排序算法:
https://zhuanlan.zhihu.com/p/37456564
https://zhuanlan.zhihu.com/p/124356219
https://www.php.cn/js-tutorial-463276.html
(1)归并排序:
function merge(left, right){
let result = [];
while(left.length && right.length){
if(left[0] <= right[0]){
result.push(left.shift())
}else{
result.push(right.shift())
}
}
return result = [...result, ...left, ...right]
}
function mergeSort(arr){
let len = arr.length;
if(len < 2){
return arr;
}
let middle = Math.floor(len/2),
left = arr.slice(0,middle),
right = arr.slice(middle);
return merge(mergeSort(left), mergeSort(right))
}