Created
August 2, 2025 08:02
-
-
Save Hayao0819/73410f391d201d9648bc88176089a9f0 to your computer and use it in GitHub Desktop.
クイックソートが動かない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runghc | |
class QuickSortable a where | |
pickPivot :: [a] -> a | |
pickPivot (top : _) = top | |
before :: Ord a => a -> [a] -> [a] | |
before pivot arr = filter (\n -> n < pivot) arr | |
after :: Ord a => a -> [a] -> [a] | |
after pivot arr = filter (\n -> n >= pivot) arr | |
instance Ord a => QuickSortable a | |
quicksort :: Ord a => [a] -> [a] | |
quicksort [] = [] | |
quicksort arr = sortedBefore ++ [pivot] ++ sortedAfter | |
where | |
pivot = pickPivot arr | |
sortedBefore = quicksort (before pivot arr) | |
sortedAfter = quicksort (after pivot arr) | |
main = do | |
print (quicksort ([1, 2, 4, 2, 7, 9, 6] :: [Int])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment