Skip to content

Instantly share code, notes, and snippets.

@BillyBadBoy
Created October 4, 2016 16:43
Show Gist options
  • Save BillyBadBoy/86df795c705e83b8dd4a29966fa2fa50 to your computer and use it in GitHub Desktop.
Save BillyBadBoy/86df795c705e83b8dd4a29966fa2fa50 to your computer and use it in GitHub Desktop.
balanceTree :: Tree -> Tree
balanceTree t = go $ (sort . tree2list) t
where go [] = Leaf
go ns = let m = length ns `div` 2
in Node (ns !! m) (go $ take m ns) (go $ drop (m + 1) ns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment