123456789101112131415161718192021222324252627282930 |
- --Define the Bilist type
- data Bilist a = Bilist [a] [a] deriving (Show, Eq)
- bilist_ref (Bilist l r) pos = (l !! pos, r !! pos)
- --Define oddeven
- oddeven :: [a] -> Bilist a
- oddeven l = oddevenh l [] []
- oddevenh :: [a] -> [a] -> [a] -> Bilist a
- oddevenh [] ev od = Bilist ev od
- oddevenh (x:xs) ev od = oddevenh xs od (ev++[x])
- --Define the inverse of oddeven
- inv_oddeven :: Bilist a -> [a]
- inv_oddeven (Bilist [] []) = []
- inv_oddeven (Bilist (l:ls) (r:rs)) = [l] ++ [r] ++ (inv_oddeven (Bilist ls rs))
- inv_oddeven2 :: Bilist a -> [a]
- inv_oddeven2 (Bilist l r) = foldl (++) [] $ map (\(x,y) -> [x,y]) $ zip l r
- bilist_max (Bilist (l:ls) (r:rs)) = bilist_maxh (Bilist ls rs) 2 (l+r) 1
- bilist_maxh (Bilist (l:ls) (r:rs)) pos curmax maxpos |
- l+r > curmax = bilist_maxh (Bilist ls rs) (pos+1) (l+r) pos
- bilist_maxh (Bilist (l:ls) (r:rs)) pos curmax maxpos =
- bilist_maxh (Bilist ls rs) (pos+1) curmax maxpos
- bilist_maxh (Bilist [] []) pos curmax maxpos = maxpos
|