いろんな言語で宿題スレat TECH
いろんな言語で宿題スレ - 暇つぶし2ch581:デフォルトの名無しさん
09/07/28 13:18:26
>>577
-- Haskell

import Data.Function (on)

merge :: (Ord a) => [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge a@(x:xs) b@(y:ys) | x < y = x : merge xs b
| otherwise = y : merge a ys

msort :: (Ord a) => [a] -> [a]
msort [] = []
msort [x] = [x]
msort xs = uncurry (merge `on` msort) $ splitAt ((length xs) `div` 2) xs

main = print $ msort [4,1,2,7,5]


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch