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=[9,5,2,7,8],i=1,j=1,temp=0;
    console.log("原:"+nums);
    for(i=1;i<nums.length;i++){
        console.log("插入第"+(i+1)+"個:"+nums[i]);
        for(j=i;j>0;j--){
            
            if(nums[j]>nums[j-1]){
                temp=nums[j];
                nums[j]=nums[j-1];
                nums[j-1]=temp;
                console.log("後:"+nums);
            }else{
                console.log("後:"+nums);
                break;
            }
            
        }
    }
    //window.alert(nums);
});
Output 300px

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

Dismiss x
public
Bin info
yaoyao34pro
0viewers