### changeset 49:d654fdecdcd0

Wrote bubble sort with modified calculate
author Yasutaka Higa Mon, 17 Nov 2014 10:23:38 +0900 820af7cc8485 06f3ca01572d delta.hs 1 files changed, 7 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
```--- a/delta.hs	Mon Nov 17 10:10:25 2014 +0900
+++ b/delta.hs	Mon Nov 17 10:23:38 2014 +0900
@@ -26,16 +26,8 @@
instance Functor Delta where
fmap f (Delta xs x ys y) = Delta xs (f x) ys (f y)

--- not proof
-fmapS :: (Show a) => (a -> b) -> Delta a -> Delta b
-fmapS f (Delta lx x ly y) = Delta (lx ++ [(show x)]) (f x) (ly ++ [(show y)]) (f y)
-
--- not proof
-fmapSS :: (Show a) => (a -> b) -> (a -> b) -> Delta a -> Delta b
-fmapSS f g (Delta lx x ly y) = Delta (lx ++ [(show x)]) (f x) (ly ++ [(show y)]) (g y)
-
instance Applicative Delta where
-    pure f                                      = Delta [] f [] f
+    pure f                                  = Delta [] f [] f
(Delta lf f lg g) <*> (Delta lx x ly y) = Delta (lf ++ lx) (f x) (lg ++ ly) (g y)

mu :: Delta (Delta a) -> Delta a
@@ -72,7 +64,10 @@

bubbleSort :: [Int] -> Delta [Int]
bubbleSort [] = returnS []
-bubbleSort xs = bubbleSort remainValue >>= (\xs -> returnS \$ sortedValue : xs)
+bubbleSort xs = bubbleSort remainValue >>= (\xs -> returnSS (sortedValueL : xs)
+                                                            (sortedValueR ++ xs))
where
-        sortedValue = maximum xs
-        remainValue = filter (/= sortedValue) xs
+        maxmumValue  = maximum xs
+        sortedValueL = maxmumValue
+        sortedValueR = replicate (length \$ filter (== maxmumValue) xs) maxmumValue
+        remainValue  = filter (/= maxmumValue) xs```