aboutsummaryrefslogtreecommitdiff
path: root/comparison/Haskell/qsort-260000.hs
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:50:21 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-05-02 09:50:21 +0900
commitdf4949f8b08cbe3cfd99933d5bb14a373f47f2dd (patch)
treec516c3c45d79a4843114ddd44a83b9ca87250cb7 /comparison/Haskell/qsort-260000.hs
parent7ea48cd96551247ecc763a5e42404ffa3464d0b0 (diff)
parent779860e35f5c67c7fd48ef876784f87afcfdb321 (diff)
downloadinpla-df4949f8b08cbe3cfd99933d5bb14a373f47f2dd.tar.gz
inpla-df4949f8b08cbe3cfd99933d5bb14a373f47f2dd.zip
Merge branch 'develop'
Diffstat (limited to 'comparison/Haskell/qsort-260000.hs')
-rw-r--r--comparison/Haskell/qsort-260000.hs43
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)