Advertisement
Guest User

Untitled

a guest
Oct 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.69 KB | None | 0 0
  1. bst_insert(Bst, Key) when Bst == {} -> {Key, null, null};
  2. bst_insert({Root, Left, Right}, Key) when Root > Key ->
  3.   {Root, bst_insert(Left, Key), Right};
  4. bst_insert({Root, Left, Right}, Key) when Root < Key ->
  5.   {Root, Left, bst_insert(Right, Key)};
  6. bst_insert({Root, Left}, Key) -> {Root, Left, Key};
  7. bst_insert(Root, Key) -> {Root, Key, null}.
  8.  
  9. bst_search(Bst, _) when Bst == {} -> false;
  10. bst_search({Root, _, _}, Key) when Root == Key -> true;
  11. bst_search({Root, Left, _}, Key) when Root > Key ->
  12.   bst_search(Left, Key);
  13. bst_search({Root, _, Right}, Key) when Root < Key ->
  14.   bst_search(Right, Key);
  15. bst_search(Root, Key) ->
  16.   if
  17.     Root == Key -> true;
  18.     Root /= Key -> false
  19.   end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement