diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-02 09:49:01 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-02 09:49:01 +0900 |
| commit | 8c7809d024e85d0a8acfb794a4db41b0e4bc13e6 (patch) | |
| tree | 25ac81bad7be415d7cf75457275f7161d79f9f10 /comparison/Haskell/qsort-260000.hs | |
| parent | 429543c748aaf81b2a4207318eb5a05259469b21 (diff) | |
| download | inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.tar.gz inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.zip | |
v0.8.2-1
Diffstat (limited to 'comparison/Haskell/qsort-260000.hs')
| -rw-r--r-- | comparison/Haskell/qsort-260000.hs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/comparison/Haskell/qsort-260000.hs b/comparison/Haskell/qsort-260000.hs new file mode 100644 index 0000000..7115121 --- /dev/null +++ b/comparison/Haskell/qsort-260000.hs @@ -0,0 +1,43 @@ +{- +(* http://www.codecodex.com/wiki/Insertion_sort#Standard_ML *) +-} +import System.Random + +qsort [] = [] +qsort [x] = [x] +qsort (x:xs) = (qsort left) ++ [x] ++ (qsort right) + where (left, right) = part x xs + +part pivot [] = ([], []) +part pivot (x:xs) + | x<pivot = (x:below, above) + | otherwise = (below, x:above) + where + (below, above) = part pivot xs + + +{- +main = print $ qsort [3,2,8,5] +-} + + +randomList :: Int -> IO([Int]) +randomList 0 = return [] +randomList n = do + r <- randomRIO (1,10000) + rs <- randomList (n-1) + return (r:rs) + + +validation [] = True +validation (x:xs) = validation_cons x xs +validation_cons x [] = True +validation_cons x (y:ys) = + if x<=y then validation_cons y ys + else False + + +main = do + list <- randomList 260000 + let sorted = qsort list + print (validation sorted) |
