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)