changeset 48:820af7cc8485

Wrote >>= style bubble sort
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Mon, 17 Nov 2014 10:10:25 +0900
parents 1aefea69f71b
children d654fdecdcd0
files delta.hs
diffstat 1 files changed, 4 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/delta.hs	Tue Nov 11 14:01:31 2014 +0900
+++ b/delta.hs	Mon Nov 17 10:10:25 2014 +0900
@@ -71,23 +71,8 @@
 primeCount x = generator x >>= primeFilter >>= count
 
 bubbleSort :: [Int] -> Delta [Int]
-bubbleSort = rightReverse . bubbleSortDelta . returnS
-
-bubbleSortDelta :: Delta [Int] -> Delta [Int]
-bubbleSortDelta (Delta lx [] ly []) = (Delta lx [] ly [])
-bubbleSortDelta xs = fmapSS (\x -> (replicate maxNumCount maxNum) ++ x)
-                            (\y -> (replicate minNumCount minNum) ++ y)
-                            (bubbleSortDelta $ fmapSS remainListMax remainListMin xs)
+bubbleSort [] = returnS []
+bubbleSort xs = bubbleSort remainValue >>= (\xs -> returnS $ sortedValue : xs)
     where
-        leftValue      = deltaLeft xs
-        rightValue     = deltaRight xs
-        maxNum         = maximum leftValue
-        minNum         = minimum rightValue
-        remainListMax  = filter (/= maxNum)
-        remainListMin  = filter (/= minNum)
-        maxNumCount    = (length leftValue)  - (length $ remainListMax leftValue)
-        minNumCount    = (length rightValue) - (length $ remainListMin rightValue)
-
-
-rightReverse :: Delta [Int] -> Delta [Int]
-rightReverse d = fmapSS id reverse d
+        sortedValue = maximum xs
+        remainValue = filter (/= sortedValue) xs