reordered quicksort
This commit is contained in:
parent
f00fcf6bd2
commit
789774d802
1 changed files with 10 additions and 10 deletions
|
|
@ -2,6 +2,13 @@ data List a where
|
||||||
Nil : List a
|
Nil : List a
|
||||||
Cons : a -> List a -> List a
|
Cons : a -> List a -> List a
|
||||||
|
|
||||||
|
main = printList (quicksort (mkDescList 1000 0))
|
||||||
|
|
||||||
|
mkDescList : Int -> Int -> List Int
|
||||||
|
mkDescList from to = case from == to of
|
||||||
|
True => Nil
|
||||||
|
False => Cons from (mkDescList (from - 1) to)
|
||||||
|
|
||||||
quicksort : List Int -> List Int
|
quicksort : List Int -> List Int
|
||||||
quicksort xs = case xs of
|
quicksort xs = case xs of
|
||||||
Nil => Nil
|
Nil => Nil
|
||||||
|
|
@ -9,10 +16,6 @@ quicksort xs = case xs of
|
||||||
let bigger = quicksort (filter (\y. a < y) xs) in
|
let bigger = quicksort (filter (\y. a < y) xs) in
|
||||||
smaller ++ (Cons a bigger)
|
smaller ++ (Cons a bigger)
|
||||||
|
|
||||||
.++ list1 list2 = case list1 of
|
|
||||||
Nil => list2
|
|
||||||
Cons x xs => Cons x (xs ++ list2)
|
|
||||||
|
|
||||||
filter : (a -> Bool) -> List a -> List a
|
filter : (a -> Bool) -> List a -> List a
|
||||||
filter p xs = case xs of
|
filter p xs = case xs of
|
||||||
Nil => Nil
|
Nil => Nil
|
||||||
|
|
@ -20,9 +23,6 @@ filter p xs = case xs of
|
||||||
True => Cons x (filter p xs)
|
True => Cons x (filter p xs)
|
||||||
False => filter p xs
|
False => filter p xs
|
||||||
|
|
||||||
mkDescList : Int -> Int -> List Int
|
.++ list1 list2 = case list1 of
|
||||||
mkDescList from to = case from == to of
|
Nil => list2
|
||||||
True => Nil
|
Cons x xs => Cons x (xs ++ list2)
|
||||||
False => Cons from (mkDescList (from - 1) to)
|
|
||||||
|
|
||||||
main = printList (quicksort (mkDescList 1000 0))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue