Skip to content

Instantly share code, notes, and snippets.

@denkiwakame
Last active August 29, 2015 13:57
Show Gist options
  • Save denkiwakame/9466863 to your computer and use it in GitHub Desktop.
Save denkiwakame/9466863 to your computer and use it in GitHub Desktop.
てきとうだった
#!/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