Selection sort

<!DOCTYPE html>

<html lang="en">

    <head>

        <meta charset="utf-8">

    </head>

    <body>

<script type="text/javascript">

    Array.prototype.selection_sort = function(){

        var i, j, min, temp;

        for (i = 0; i < this.length - 1; i++) {
min = i;
for (j = i + 1; j < this.length; j++) {
if(this[min] > this[j]){
min = j;
}
temp = this[min];
this[min] = this[i];
this[i] = temp;
};
}; return this; } var num = [7, 3, 2, 100, 5, 4, 0]; num.selection_sort(); for (var i = 0; i < num.length; i++) document.body.innerHTML += num[i] + " "; </script> </body> </html>
上一篇:C#DataTable与Model互转


下一篇:oracle和postgresql 递归查询父子关系记录语法区别