Detailed explanation of bubble sorting in sorting in JS

小云云
Release: 2018-03-19 17:23:52
Original
1693 people have browsed it

This article mainly shares with you the detailed explanation of bubble sorting in sorting in JS. This article is mainly in the form of code and hopes to help everyone.

window.onload=function() { var arr=[1,14,4,2,6,10]; arr.sort(function(obj1,obj2){ if(obj1>obj2) {return 1;} else if (obj1==obj2) {return 0;} else {return -1;} }); console.log(arr); // var f1=function(a,b){return a-b;} arr.sort(f1); alert(arr); // //鍐掓场鎺掑簭 function mysort(arr) { var temp; for(var i=0;iarr[j+1]){ isSort=false; temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp;} } if(isSort) {break;} } return arr; }
Copy after login

Related recommendations:

Detailed explanation of bubble sort in JavaScript

Js bubble sort and quick sort detailed explanation

Simple understanding of PHP bubble sort

The above is the detailed content of Detailed explanation of bubble sorting in sorting in JS. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!