You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionquickSort(arr){if(Object.prototype.toString.call(arr)!='[object Array]'){return'Error: Not Array Object';}if(arr.length<=1){returnarr;}varmiddle=Math.floor(arr.length/2);varpivot=arr.splice(middle,1)[0];varleft=[],right=[];for(vari=0;i<arr.length;i++){if(arr[i]<pivot){left.push(arr[i]);}else{right.push(arr[i]);}}return(quickSort(left).concat([pivot],quickSort(right)));}
三种常用的简单排序算法(JavaScript描述),默认从小到大排列,下面是code:
对于Javascript来说,推荐快速排序算法,其执行效率比较高。
The text was updated successfully, but these errors were encountered: