learnyouanelm / learnyouanelm.github.io

“Learn You an Elm!”, based on LYAH by Miran Lipovača
http://learnyouanelm.github.io/
93 stars 16 forks source link

the quick sort definition has something wrong #9

Closed Hobinx closed 6 years ago

Hobinx commented 8 years ago

The definition forgot to recursively call itself, and the order of the predicates should be swapped, may be:

quicksort : List comparable -> List comparable
quicksort list =
  case list of
    [] -> []
    (x::xs) -> 
      let 
        smallerSorted = quicksort (List.filter ((>) x) xs)
        biggerSorted = quicksort (List.filter ((<=) x) xs)
      in
        smallerSorted ++ [x] ++ biggerSorted
deadfoxygrandpa commented 8 years ago

Thanks, you're right. Your definition works.

Hobinx commented 8 years ago

Thanks, glad to hear that.