|
![](/i/fill.gif) |
Darren New wrote:
> Interesting. :-)
"while (!(*i < *--j)) {}"
Um, yeah, "interesting" would be the term I'd use. WTF? o_O
Personally, I'd do it this way:
nextP :: Ord x => [x] -> Maybe [x]
nextP [] = Nothing
nextP [x] = Nothing
nextP xs =
case split (reverse xs) of
([] , _ ) -> Nothing
(ss', ps') ->
let
p0 = head ps'
(ss0, ss1) = span (p0 >=) ss'
s0 = head ss1
ps = reverse (s0 : tail ps')
ss = ss0 ++ [p0] ++ tail ss1
in Just (ps ++ ss)
split :: Ord x => [x] -> ([x], [x])
split [] = ([], [])
split (x:xs) = work x xs
where
work x0 [] = ([x0], [])
work x0 (x:xs)
| x >= x0 = let (ys,zs) = work x xs in (x0:ys, zs)
| otherwise = ([x0], x:xs)
Post a reply to this message
|
![](/i/fill.gif) |