Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ewHeap {
- constructor() {
- this.root = new Node();
- this.size = 0;
- }
- addNode(value) {
- let currentNode = this.root;
- while (currentNode != undefined) {
- if (currentNode.hasLeftChild()) {
- currentNode = currentNode.leftChild;
- break;
- } else if (currentNode.hasRightChild()) {
- currentNode = currentNode.rightChild;
- break;
- }
- }
- currentNode.value = value;
- this.size++;
- }
- }
- class Node{
- constructor(value){
- this.value = value;
- this.parent = null;
- this.leftChild = null;
- this.rightChild = null;
- }
- addLeftChild(value){
- this.leftChild = new Node(value);
- }
- addRightChild(value){
- this.rightChild = new Node(value);
- }
- setParent(node){
- this.parent = node;
- }
- hasLeftChild(){
- return (this.leftChild != null);
- }
- hasRightChild(){
- return (this.rightChild != null);
- }
- }
Add Comment
Please, Sign In to add comment