Created
January 31, 2015 16:50
-
-
Save karenpeng/75e3225c68453b07498e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quickSort(arr) { | |
var less = more = pivots = []; | |
if (arr.length > 1) { | |
pivot = arr[0]; | |
arr.forEach(function (i) { | |
if (i < pivot) { | |
less.push(i); | |
console.log(i) | |
} else if (i > pivot) { | |
more.push(i); | |
} else { | |
pivots.push(i); | |
} | |
}); | |
console.log('! ' + less) | |
//console.log(less + ' ! ' + pivots + ' ! ' + more) | |
} else { | |
return arr; | |
} | |
//quickSort(less); | |
//quickSort(more); | |
return less.concat(pivots).concat(more); | |
} | |
//this program will logs out | |
// 4 | |
// 6 | |
// 6 | |
// 2 | |
// 7 | |
// ! 8,4,6,13,6,2,7,46,32,12,53,124 | |
function quickSort(arr) { | |
var less = [], | |
more = [], | |
pivots = []; | |
if (arr.length > 1) { | |
pivot = arr[0]; | |
arr.forEach(function (i) { | |
if (i < pivot) { | |
less.push(i); | |
console.log(i) | |
} else if (i > pivot) { | |
more.push(i); | |
} else { | |
pivots.push(i); | |
} | |
}); | |
console.log('! ' + less) | |
} else { | |
return arr; | |
} | |
//quickSort(less); | |
//quickSort(more); | |
return less.concat(pivots).concat(more); | |
} | |
//while this program will logs out | |
// 4 | |
// 6 | |
// 6 | |
// 2 | |
// 7 | |
// ! 4,6,6,2,7 | |
/* | |
Be careful of the equal sign!! | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment