Last active
August 29, 2015 13:57
-
-
Save denkiwakame/9466863 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
#!/usr/bin/ruby | |
def qsort(first,last,ary) | |
if first >= last | |
return | |
end | |
target = ary[first] | |
buf1 = Array.new | |
buf2 = Array.new | |
for i in first+1..last | |
if ary[i] < target | |
buf1.push ary[i] | |
else | |
buf2.push ary[i] | |
end | |
end | |
ary[first..last] = buf1 + [target] + buf2 | |
qsort(first, first+buf1.length-1, ary) | |
qsort(last-buf2.length+1, last, ary) | |
end | |
sary = Array.new | |
N = 10 | |
N.times do |i| | |
sary[i] = rand(N) | |
end | |
p sary | |
qsort(0, N-1, sary) | |
p sary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment