Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BinaryTree {
- constructor() {
- this.root = null;
- this._size = 0;
- }
- insert(data) {
- var node = new Node(data, null, null);
- if (this.root == null) {
- this.root = node.data;
- } else {
- return insertR(this.root, data);
- }
- this._size += 1;
- }
- contains(data) {
- if (this.root == null) {
- return false;
- } else {
- return containsR(this.root, value);
- }
- }
- remove(data) {
- }
- size() {
- }
- isEmpty() {
- }
- // private methods
- }
- var insertR = function(node, value) {
- if (node.data > value) {
- if (node.left == null) {
- node.left = value;
- } else {
- insertR(node.left, value);
- }
- } else {
- if (node.right == null) {
- node.right = value;
- } else {
- insertR(node.right, value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement