I am trying to implement bubble sort to sort my list by priority. For example, the list is of the following format with the 3rd element being priority:
[("Ted", 100, 3), ("Boris", 100, 1), ("Sam", 100, 2)]
I have tried the standard bubble sort method below, however this did not work. Any suggestions would be appreciated.
bubbleSort :: (Ord t) => [t] -> [t]
bubbleSort a = loop (length a) bubble a
bubble :: (Ord t) => [t] -> [t]
bubble (a:b:c) | a < b = a : bubble (b:c)
| otherwise = b : bubble (a:c)
bubble (a:[]) = [a]
bubble [] = []
loop :: (Num a, Ord a) => a -> (t -> t) -> t -> t
loop num f x | num > 0 = loop (num-1) f x'
| otherwise = x
where x' = f x