Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://adrianmejia.com/data-structures-for-beginners-trees-binary-search-tree-tutorial/
- // https://www.youtube.com/c/BackToBackSWE
- // binary search tree
- const LEFT = 0;
- const RIGHT = 1;
- class TreeNode {
- constructor(value) {
- this.value = value;
- this.descendants = [];
- this.parent = null;
- }
- get left() {
- return this.descendants[LEFT];
- }
- set left(node) {
- this.descendants[LEFT] = node;
- if (node) {
- node.parent = this;
- }
- }
- get right() {
- return this.descendants[RIGHT];
- }
- set right(node) {
- this.descendants[RIGHT] = node;
- if (node) {
- node.parent = this;
- }
- }
- }
- ///
- class BinarySearchTree {
- constructor() {
- this.root = null;
- this.size = 0;
- }
- add(value) { /* ... */ }
- find(value) { /* ... */ }
- remove(value) { /* ... */ }
- getMax() { /* ... */ }
- getMin() { /* ... */ }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement