Skip to content
Browse files

simplified stupid quicksort example

  • Loading branch information...
1 parent bd4e28b commit 6e06162e0433e199d231fb6f6550d98ddceecafc @bakkdoor committed Apr 9, 2012
Showing with 11 additions and 9 deletions.
  1. +11 −9 examples/stupid_quicksort.fy
View
20 examples/stupid_quicksort.fy
@@ -1,12 +1,14 @@
-def quicksort: arr {
- match arr size {
- case (0..1) -> arr
- case _ ->
- piv = arr at: $ rand(arr size)
- (quicksort: $ arr select: |x| { x < piv }) + (quicksort: $ arr select: |x| { x >= piv })
+class Array {
+ def quicksort {
+ match size {
+ case 0 -> self
+ case _ ->
+ (rest select: @{ < first } . quicksort) + [first] + (rest select: @{ >= first } . quicksort)
+ }
}
}
-arr = 0 upto: 10 . map: { rand(100) }
-arr inspect println
-quicksort: arr . inspect println
+(1..10) map: { 100 random } . tap: @{
+ inspect println
+ quicksort inspect println
+}

0 comments on commit 6e06162

Please sign in to comment.
Something went wrong with that request. Please try again.