这是我照着书上敲的归并排序,可是控制台输出merg函数while判断中的length为undefinedfunctionsplitMergeSort(arr){varlen=arr.length;while(len==1){returnarr;}varmid=Math.floor(len/2);varleft=arr.slice(0,mid),right=arr.slice(mid,len);returnsplitMergeSort(merge(left),merge(right))}//合并函数functionmerge(arr1,arr2){varresult=[];varl=0;varr=0;while(lif(arr1[l] result.push(arr1[l++]) }else{result.push(arr2[r++])}}while(lresult.push(arr1[l++]) }while(rresult.push(arr2[r++]) }}
万千封印
慕田峪4524236
相关分类