From 789774d80293aedb9537da1ac3e99fab2cf10150 Mon Sep 17 00:00:00 2001 From: sebastianselander Date: Wed, 24 May 2023 16:06:10 +0200 Subject: [PATCH] reordered quicksort --- demo/quicksort.crf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/demo/quicksort.crf b/demo/quicksort.crf index 5728051..e97af3a 100644 --- a/demo/quicksort.crf +++ b/demo/quicksort.crf @@ -2,6 +2,13 @@ data List a where Nil : 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 xs = case xs of Nil => Nil @@ -9,10 +16,6 @@ quicksort xs = case xs of let bigger = quicksort (filter (\y. a < y) xs) in 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 @@ -20,9 +23,6 @@ filter p xs = case xs of True => Cons x (filter p xs) False => filter p xs -mkDescList : Int -> Int -> List Int -mkDescList from to = case from == to of - True => Nil - False => Cons from (mkDescList (from - 1) to) - -main = printList (quicksort (mkDescList 1000 0)) +.++ list1 list2 = case list1 of + Nil => list2 + Cons x xs => Cons x (xs ++ list2)