Created
September 22, 2012 03:48
-
-
Save monkyz/3765052 to your computer and use it in GitHub Desktop.
function quicksort
This file contains hidden or 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
Simple version | |
In simple pseudocode, the algorithm might be expressed as this: | |
function quicksort('array') | |
if length('array') ≤ 1 | |
return 'array' // an array of zero or one elements is already sorted | |
select and remove a pivot value 'pivot' from 'array' | |
create empty lists 'less' and 'greater' | |
for each 'x' in 'array' | |
if 'x' ≤ 'pivot' then append 'x' to 'less' | |
else append 'x' to 'greater' | |
return concatenate(quicksort('less'), 'pivot', quicksort('greater')) // two recursive calls | |
-------------------------------------------------------------------------------------------------------- | |
js version: | |
var quicksort = function (array){ | |
if (array.length <= 1){ | |
return array;} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment