Skip to content

Instantly share code, notes, and snippets.

@caglarorhan
Created October 20, 2017 07:28
Show Gist options
  • Save caglarorhan/bf45b88689c2a8496d95b2aed9289e85 to your computer and use it in GitHub Desktop.
Save caglarorhan/bf45b88689c2a8496d95b2aed9289e85 to your computer and use it in GitHub Desktop.
Bubble Sort Algorithm
function bubleSort(array){
var sArr = array;
var sArrLength = sArr.length;
for(var sayac=0; sayac<sArrLength-1; sayac++){
for(var i=0; i<sArrLength-1-sayac; i++){
var s= parseInt(i+1);
if(sArr[i]>sArr[s]){
var first = sArr[i];
var second = sArr[s];
sArr[i]=second; sArr[s]=first;
}
}
}
return sArr;
}
bubleSort([31,5,65,3,12,8,21,2,17,1,4,9,-1,-9,-12,-7,0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment