Skip to content

Instantly share code, notes, and snippets.

@Abhiroop
Last active October 30, 2017 11:58
Show Gist options
  • Save Abhiroop/01522e47844ece3cc1b3388bcde1799d to your computer and use it in GitHub Desktop.
Save Abhiroop/01522e47844ece3cc1b3388bcde1799d to your computer and use it in GitHub Desktop.
insert :: (Ord a) => a -> Tree a -> Tree a
insert x s = makeBlack $ ins s
where ins E = T R E x E
ins (T color a y b)
| x < y = balance color (ins a) y b
| x == y = T color a y b
| x > y = balance color a y (ins b)
makeBlack (T _ a y b) = T B a y b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment