Talk:Insertion sort

From Wikisource
Jump to navigation Jump to search

Fixed up the insertion sort and verified in hugs. Type specification was incorect, and execution led to cause exhaustion for insert a1 []


insert :: (Ord a) => a -> OrdList a -> OrdList a
insert a1 [] = [a1]
insert a1 (a2:as)
     | a1 <= a2 = a1:a2:as 
     | otherwise = a2:insert a1 as

can somebody fix my c++ code? i have no idea how to change it