Jump to content

Algoritmo de Seleção em Haskell


crislanio_macedo
 Share

Recommended Posts

minimo :: Ord a => [a] -> a
minimo [x] = x
minimo (x:xs) = if (filter (<x) xs)== [] then x else minimo xs
remove' a [] = []
remove' a [x] = if a == x then [] else [x]
remove' a (x:xs) = [] ++ if (x == a) then xs else x:(remove' a xs)
-- selectionSort :: Ord a => [a] -> [a]
-- selectionSort :: Ord a => [a] -> [a]
selectionSort [] = []
selectionSort a@(x:xs) = head.minimo a $ selectionSort xs

Como proceder no caso acima, já que a ideia no selectionSort era pegar a cabeça da lista (elemento mínimo), e chamar o resto do da lista sem o elemento mínimo.

Edited by thoga31
GeSHi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.