Blogger Information
Blog 14
fans 0
comment 0
visits 8047
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS实现冒泡排序
「flasky」
Original
775 people have browsed it

JS实现冒泡排序

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>冒泡算法</title>
  6. </head>
  7. <body>
  8. <script>
  9. var arr=[6,5,1,2,4,3,8,9,7,32,44,22,53,23,25,67,64,33,76,78,33,56,45,23,22,4,12,15,14];
  10. for (j=0;j<arr.length-1;j++){
  11. for (i=0;i<arr.length-1;i++)
  12. {
  13. var temp='';
  14. if (arr[i]>arr[i+1]){
  15. temp=arr[i];
  16. arr[i]=arr[i+1];
  17. arr[i+1]=temp;
  18. }
  19. }
  20. }
  21. console.log(arr)
  22. </script>
  23. </body>
  24. </html>

运行结果如下

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post