Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created February 26, 2017 05:20
Show Gist options
  • Select an option

  • Save blackknight36/2038d0955eb6d4d23577c81c0aa5b651 to your computer and use it in GitHub Desktop.

Select an option

Save blackknight36/2038d0955eb6d4d23577c81c0aa5b651 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
def quicksort(ar)
return ar if ar.length < 2
left = []
equal = []
right = []
p = ar[0]
ar.each do |i|
left.push(i) if i < p
equal.push(i) if i == p
right.push(i) if i > p
end
sub = quicksort(left) + equal + quicksort(right)
for x in sub
printf("%d ", x)
end
printf("\n")
return sub
end
cnt = gets.chomp.to_i
ar = STDIN.gets.chomp.split(" ").map{|x|x.to_i};
quicksort(ar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment