This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data BinaryTree a = EmptyTree | Node a (BinaryTree a) (BinaryTree a) | |
deriving (Show) | |
treeInsert :: Ord a => a -> BinaryTree a -> BinaryTree a | |
treeInsert el EmptyTree = Node el EmptyTree EmptyTree | |
treeInsert el (Node a left right) | |
| el == a = Node el left right | |
| el < a = Node a (treeInsert el left) right | |
| el > a = Node a left (treeInsert el right) |