Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class BinaryTree {
  2. constructor() {
  3. this.root = null;
  4. this._size = 0;
  5. }
  6.  
  7. insert(data) {
  8. var node = new Node(data, null, null);
  9.  
  10. if (this.root == null) {
  11. this.root = node.data;
  12. } else {
  13. return insertR(this.root, data);
  14. }
  15.  
  16. this._size += 1;
  17. }
  18.  
  19. contains(data) {
  20. if (this.root == null) {
  21. return false;
  22. } else {
  23. return containsR(this.root, value);
  24. }
  25. }
  26.  
  27. remove(data) {
  28.  
  29. }
  30.  
  31. size() {
  32.  
  33. }
  34.  
  35. isEmpty() {
  36.  
  37. }
  38. // private methods
  39.  
  40.  
  41.  
  42.  
  43.  
  44. }
  45. var insertR = function(node, value) {
  46. if (node.data > value) {
  47. if (node.left == null) {
  48. node.left = value;
  49. } else {
  50. insertR(node.left, value);
  51. }
  52. } else {
  53. if (node.right == null) {
  54. node.right = value;
  55. } else {
  56. insertR(node.right, value);
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement