Home  >  Article  >  Web Front-end  >  A simple js bubble sort example

A simple js bubble sort example

小云云
小云云Original
2018-03-02 13:14:361464browse

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

<br>
rb.data是一个数组对象
//根据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;
        }
    }
}

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!

Statement:
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