-
-
Save cia-rana/f2a02c21b69f0b80fe29fe6c3f2fc63b to your computer and use it in GitHub Desktop.
Rubyでのクイックソート
This file contains 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 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