Skip to content

Instantly share code, notes, and snippets.

@cia-rana
Forked from katryo/quick_sort.rb
Last active July 10, 2017 15:19
Show Gist options
  • Save cia-rana/f2a02c21b69f0b80fe29fe6c3f2fc63b to your computer and use it in GitHub Desktop.
Save cia-rana/f2a02c21b69f0b80fe29fe6c3f2fc63b to your computer and use it in GitHub Desktop.
Rubyでのクイックソート
def quicksort(seq)
return seq if seq.size.zero?
pivot = seq.shift
right = []
left = []
seq.each{|e|
if e <= pivot
left.push(e)
else
right.push(e)
end
}
quicksort(left) + [pivot] + quicksort(right)
end
arr = [1,53,36,77,22,100,4,20]
p(quicksort(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment