crislanio_macedo Posted March 9, 2015 at 05:11 PM Report Share #579024 Posted March 9, 2015 at 05:11 PM (edited) 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 March 9, 2015 at 08:50 PM by thoga31 GeSHi Link to comment Share on other sites More sharing options...
crislanio_macedo Posted March 10, 2015 at 12:39 AM Author Report Share #579043 Posted March 10, 2015 at 12:39 AM selectionSort:: (Ord a) => [a]->[a] selectionSort [] = [] selectionSort xs = [x] ++ selectionSort (remove' x xs) where x = minimo xs Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now