国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JavaScript實現快速排序的方法

2024-05-06 16:24:08
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了JavaScript實現快速排序的方法,實例分析了javascript快速排序的相關實現技巧,具有一定參考借鑒價值,需要的朋友可以參考下

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

 

 
  1. <html> 
  2. <head> 
  3. <script> 
  4. function quickSort(input) { 
  5. if (input.length <= 1) return input; 
  6. var pivot = Math.floor(Math.random()*input.length) 
  7. var less = [], greater=[]; 
  8. var pivotElem = input.splice(pivot,1) 
  9. for (x in input) { 
  10. if (input[x] <= pivotElem[0]) 
  11. less.push(input[x]) 
  12. else 
  13. greater.push(input[x]) 
  14. return [].concat(quickSort(less),pivotElem,quickSort(greater)); 
  15. input = [] 
  16. inputSize = 1000 
  17. highestInputValue = 100 
  18. for (i=0;i<inputSize;i++) { 
  19. input.push(Math.floor(Math.random()*highestInputValue)) 
  20. document.writeln(quickSort(input)) 
  21. </script> 
  22. </head> 
  23. </body> 
  24. </html> 

希望本文所述對大家的javascript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 宁陕县| 宝丰县| 太谷县| 大洼县| 古交市| 汝州市| 昌邑市| 庄河市| 贡觉县| 富川| 偏关县| 德化县| 防城港市| 兴隆县| 浦城县| 英超| 且末县| 盐津县| 繁昌县| 扶风县| 景洪市| 承德市| 永城市| 迁安市| 调兵山市| 南木林县| 宝清县| 通江县| 靖边县| 汤阴县| 百色市| 伊吾县| 泾阳县| 鄢陵县| 鄂托克前旗| 赤水市| 正定县| 开封县| 扶绥县| 昌都县| 东乌珠穆沁旗|