Home > Web Front-end > JS Tutorial > body text

A simple js bubble sort example

小云云
Release: 2018-03-02 13:14:36
Original
1389 people have browsed it

This article mainly shares with you a simple js bubble sorting sample code, I hope it can help you.

<br>
Copy after login
rb.data是一个数组对象
Copy after login
//根据itemPos大小冒泡排序for(var i=0;i<rb.data.length;i++){    for(var j = 0 ;j<rb.data.length-1-i;j++){        if(rb.data[j].itemPos>rb.data[j+1].itemPos){            var temp=rb.data[j];
            rb.data[j]=rb.data[j+1];
            rb.data[j+1]=temp;
        }
    }
}
Copy after login

Related recommendations:

php bubble sorting example sharing

php bubble sorting array sorting method from small to large

Detailed explanation of bubble sorting method

The above is the detailed content of A simple js bubble sort example. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
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!