Created
February 15, 2012 20:02
-
-
Save mizchi/1838619 to your computer and use it in GitHub Desktop.
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
def qsort (arr, left=0, right=arr.length-1, pl=left, pr=right) | |
x = arr[(left+right)/2] | |
begin | |
pl+=1 while arr[pl] < x | |
pr-=1 while arr[pr] > x | |
arr[pl], arr[pr] = arr[pr], arr[pl] | |
end while arr[pl] != arr[pr] | |
qsort(arr, left, pl-1) if pl-left > 1 | |
qsort(arr, pr+1, right) if right-pr > 1 | |
end | |
arr =(1..10).sort_by {rand} | |
qsort(arr) | |
p "result:#{arr}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment