Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
$().ready(function(){
    var data=[9,4,7,3,8,2,1,10];
    bubble(data,0,data.length-1);
    alert(data);
});
function bubble(data,start,end){
        if(end<=0){
            return;
        }else{
            if(data[start]>data[end]){
                swap(data,start,end);
            }
            start++;
            if(start==end){
                start=0;
                end--;
            }
            bubble(data,start,end);
        }
        
}
function swap(data,i,j){
    var temp=data[i];
    data[i]=data[j];
    data[j]=temp;
}
Output 300px

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

Dismiss x
public
Bin info
yaoyao34pro
0viewers