* @constructor * A class for AVL Tree * @argument comp - A function used by AVL Tree For Comparison * If no argument is sent it uses utils.comparator
| 32 | * If no argument is sent it uses utils.comparator |
| 33 | */ |
| 34 | class AVLTree { |
| 35 | constructor(comp) { |
| 36 | /** @public comparator function */ |
| 37 | this._comp = undefined |
| 38 | this._comp = comp !== undefined ? comp : utils.comparator() |
| 39 | |
| 40 | /** @public root of the AVL Tree */ |
| 41 | this.root = null |
| 42 | /** @public number of elements in AVL Tree */ |
| 43 | this.size = 0 |
| 44 | } |
| 45 | |
| 46 | /* Public Functions */ |
| 47 | /** |
| 48 | * For Adding Elements to AVL Tree |
| 49 | * @param {any} _val |
| 50 | * Since in AVL Tree an element can only occur once so |
| 51 | * if a element exists it return false |
| 52 | * @returns {Boolean} element added or not |
| 53 | */ |
| 54 | add(_val) { |
| 55 | const prevSize = this.size |
| 56 | this.root = insert(this.root, _val, this) |
| 57 | return this.size !== prevSize |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * TO check is a particular element exists or not |
| 62 | * @param {any} _val |
| 63 | * @returns {Boolean} exists or not |
| 64 | */ |
| 65 | find(_val) { |
| 66 | const temp = searchAVLTree(this.root, _val, this) |
| 67 | return temp != null |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * |
| 72 | * @param {any} _val |
| 73 | * It is possible that element doesn't exists in tree |
| 74 | * in that case it return false |
| 75 | * @returns {Boolean} if element was found and deleted |
| 76 | */ |
| 77 | remove(_val) { |
| 78 | const prevSize = this.size |
| 79 | this.root = deleteElement(this.root, _val, this) |
| 80 | return prevSize !== this.size |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // creates new Node Object |
| 85 | class Node { |
nothing calls this directly
no outgoing calls
no test coverage detected