【发布时间】:2012-09-29 09:02:19
【问题描述】:
这是一个haskell问题:重复输入数字直到用户输入0,然后按顺序显示这些数字。
我知道如何按顺序排列 int 列表。 这是我的代码:
placeinorder :: [Int] -> [Int]
placeinorder [] = []
placeinorder [x] = [x]
placeinorder (pivot:xs) = placeinorder left ++ [pivot] ++ placeinorder right
where left = filter (<pivot) xs
right = filter (>pivot) xs
此外,我知道如何从输入中获取 Int:
getInt :: IO Int
getInt = do
line <- getLine
return (read line :: Int)
但我不知道如何将输入的数字更改为列表...然后我可以使用 placeinorder 函数。
有人可以为我编写正确的代码吗?
非常感谢!!!!
【问题讨论】: