Skip to content

Commit 57c3801

Browse files
committed
quicksort in ruby
1 parent ba31ebb commit 57c3801

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

QuickSort/Ruby/quicksort.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Array
2+
def quicksort
3+
return [] if empty?
4+
5+
pivot = delete_at(rand(size))
6+
left, right = partition(&pivot.method(:>))
7+
8+
return *left.quicksort, pivot, *right.quicksort
9+
end
10+
11+
array = [15, 23, 1, 9, 10, 2, 5]
12+
p array.quicksort
13+
end

0 commit comments

Comments
 (0)