__rain1

Untitled

Jul 9th, 2019
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ewHeap {
  2.     constructor() {
  3.         this.root = new Node();
  4.         this.size = 0;
  5.     }
  6.  
  7.     addNode(value) {
  8.         let currentNode = this.root;
  9.  
  10.         while (currentNode != undefined) {
  11.             if (currentNode.hasLeftChild()) {
  12.                 currentNode = currentNode.leftChild;
  13.                 break;
  14.             } else if (currentNode.hasRightChild()) {
  15.                 currentNode = currentNode.rightChild;
  16.                 break;
  17.             }
  18.         }
  19.  
  20.         currentNode.value = value;
  21.         this.size++;
  22.     }
  23. }
  24.  
  25. class Node{
  26.     constructor(value){
  27.         this.value = value;
  28.         this.parent = null;
  29.         this.leftChild = null;
  30.         this.rightChild = null;
  31.     }
  32.  
  33.     addLeftChild(value){
  34.         this.leftChild = new Node(value);
  35.     }
  36.    
  37.     addRightChild(value){
  38.         this.rightChild = new Node(value);
  39.     }
  40.  
  41.     setParent(node){
  42.         this.parent = node;
  43.     }
  44.  
  45.     hasLeftChild(){
  46.         return (this.leftChild != null);
  47.     }
  48.  
  49.     hasRightChild(){
  50.         return (this.rightChild != null);
  51.     }
  52. }
Add Comment
Please, Sign In to add comment