edited quicksort file for demo
This commit is contained in:
parent
4f9cb8d3b0
commit
f00fcf6bd2
2 changed files with 14 additions and 8 deletions
BIN
demo/quicksort
BIN
demo/quicksort
Binary file not shown.
|
|
@ -1,10 +1,6 @@
|
||||||
|
data List a where
|
||||||
filter : (a -> Bool) -> List a -> List a
|
Nil : List a
|
||||||
filter p xs = case xs of
|
Cons : a -> List a -> List a
|
||||||
Nil => Nil
|
|
||||||
Cons x xs => case p x of
|
|
||||||
True => Cons x (filter p xs)
|
|
||||||
False => filter p xs
|
|
||||||
|
|
||||||
quicksort : List Int -> List Int
|
quicksort : List Int -> List Int
|
||||||
quicksort xs = case xs of
|
quicksort xs = case xs of
|
||||||
|
|
@ -13,10 +9,20 @@ 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 p xs = case xs of
|
||||||
|
Nil => Nil
|
||||||
|
Cons x xs => case p x of
|
||||||
|
True => Cons x (filter p xs)
|
||||||
|
False => filter p xs
|
||||||
|
|
||||||
mkDescList : Int -> Int -> List Int
|
mkDescList : Int -> Int -> List Int
|
||||||
mkDescList from to = case from == to of
|
mkDescList from to = case from == to of
|
||||||
True => Nil
|
True => Nil
|
||||||
False => Cons from (mkDescList (from - 1) to)
|
False => Cons from (mkDescList (from - 1) to)
|
||||||
|
|
||||||
main = printList (quicksort (mkDescList 1000 0))
|
main = printList (quicksort (mkDescList 1000 0))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue