From e334605825b2d34b3ce460e010feaf89e55b7330 Mon Sep 17 00:00:00 2001 From: wesleyrcb Date: Tue, 22 Oct 2019 23:12:10 -0300 Subject: [PATCH] add bubblesort in haskell --- Sorting/BubbleSortHaskell/BSHaskell | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Sorting/BubbleSortHaskell/BSHaskell diff --git a/Sorting/BubbleSortHaskell/BSHaskell b/Sorting/BubbleSortHaskell/BSHaskell new file mode 100644 index 000000000..b10348d7f --- /dev/null +++ b/Sorting/BubbleSortHaskell/BSHaskell @@ -0,0 +1,13 @@ +bubble :: (Ord a) => [a] -> [a] +bubble [] = [] +bubble list = bubbleOrd list (length list) + +bubbleOrd :: (Ord a) => [a] -> Int -> [a] +bubbleOrd list 0 = list +bubbleOrd list n = bubbleOrd (change list) (n-1) + +change :: (Ord a) => [a] -> [a] +change [x] = [x] +change (x:y:zs) + | x > y = y : change (x:zs) + | otherwise = x : change (y:zs)