最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript實(shí)現(xiàn)快速排序的方法

 更新時(shí)間:2015年07月31日 11:25:32   作者:華宰  
這篇文章主要介紹了JavaScript實(shí)現(xiàn)快速排序的方法,實(shí)例分析了javascript快速排序的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JavaScript實(shí)現(xiàn)快速排序的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

<html>
<head>
<script>
 function quickSort(input) {
  if (input.length <= 1) return input;
  var pivot = Math.floor(Math.random()*input.length)
  var less = [], greater=[];
  var pivotElem = input.splice(pivot,1)
  for (x in input) {
   if (input[x] <= pivotElem[0])
    less.push(input[x])
   else
    greater.push(input[x])
  }
  return [].concat(quickSort(less),pivotElem,quickSort(greater));
 }
 input = []
 inputSize = 1000
  highestInputValue = 100
 for (i=0;i<inputSize;i++) {
  input.push(Math.floor(Math.random()*highestInputValue))
 }
 document.writeln(quickSort(input))
</script>
</head>
</body>
</html>

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

根河市| 临泉县| 平昌县| 濉溪县| 垣曲县| 灌阳县| 静宁县| 平凉市| 奇台县| 竹北市| 利川市| 琼中| 石嘴山市| 兴国县| 集贤县| 海兴县| 安徽省| 瑞昌市| 吉隆县| 绵竹市| 交城县| 吴川市| 墨江| 卢氏县| 鄂托克前旗| 兰溪市| 贵南县| 进贤县| 常德市| 日土县| 苗栗县| 巢湖市| 长春市| 东宁县| 朔州市| 岫岩| 邯郸市| 阜城县| 神农架林区| 高邮市| 广灵县|