Skip to content

Instantly share code, notes, and snippets.

@reinaldorauch
Created April 7, 2015 11:39
Show Gist options
  • Select an option

  • Save reinaldorauch/4422e9b38f383a9b6748 to your computer and use it in GitHub Desktop.

Select an option

Save reinaldorauch/4422e9b38f383a9b6748 to your computer and use it in GitHub Desktop.
Árvore de busca binária parcialmente implementada em Haskell
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
treeInsert :: (Ord a) => a -> Tree a -> Tree a
treeInsert x EmptyTree = Node x EmptyTree EmptyTree
treeInsert x (Node a left right)
| x == a = Node x left right
| x < a = Node a (treeInsert x left) right
| x > a = Node a left (treeInsert x right)
treeElement :: (Ord a) => a -> Tree a -> Bool
treeElement x EmptyTree = False
treeElement x (Node a left right)
| x == a = True
| x < a = treeElement x left
| x > a = treeElement x right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment