# HG changeset patch # User Yasutaka Higa # Date 1416186625 -32400 # Node ID 820af7cc848595e6a3e7aa18dbb3b5ff9ec779d1 # Parent 1aefea69f71b7564c07dd8697d717fe37f3bdc52 Wrote >>= style bubble sort diff -r 1aefea69f71b -r 820af7cc8485 delta.hs --- 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