Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>氣泡排序</title>
</head>
<body>
</body>
</html>
 
window.addEventListener("load",function(){
    console.clear();
    var nums=[8,4,9,5,2,7],i=0,j=0,temp=0;
    console.log(nums);
    for(i=1;i<nums.length;i++){
        for(j=0;j<nums.length-i;j++){
            console.log("比較",nums[j],nums[j+1]);
            if(nums[j]<nums[j+1]){
                temp=nums[j];
                nums[j]=nums[j+1];
                nums[j+1]=temp;
                console.log("交換");
            }
            console.log(nums);
        }
    }
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
yaoyao34pro
0viewers