npx standard --fix

This commit is contained in:
cclauss
2020-05-03 09:05:12 +02:00
parent e62ad2f73e
commit 856dc2f63c
47 changed files with 2240 additions and 2371 deletions

View File

@@ -1,4 +1,4 @@
/*Binary Search Tree!!
/* Binary Search Tree!!
*
* Nodes that will go on the Binary Tree.
* They consist of the data in them, the node to the left, the node
@@ -13,104 +13,102 @@
// class Node
var Node = (function () {
// Node in the tree
function Node(val) {
this.value = val;
this.left = null;
this.right = null;
function Node (val) {
this.value = val
this.left = null
this.right = null
}
// Search the tree for a value
Node.prototype.search = function (val) {
if (this.value == val) {
return this;
return this
} else if (val < this.value && this.left != null) {
return this.left.search(val);
return this.left.search(val)
} else if (val > this.value && this.right != null) {
return this.right.search(val);
return this.right.search(val)
}
return null;
};
return null
}
// Visit a node
Node.prototype.visit = function () {
// Recursively go left
if (this.left != null) {
this.left.visit();
this.left.visit()
}
// Print out value
console.log(this.value);
console.log(this.value)
// Recursively go right
if (this.right != null) {
this.right.visit();
this.right.visit()
}
};
}
// Add a node
Node.prototype.addNode = function (n) {
if (n.value < this.value) {
if (this.left == null) {
this.left = n;
this.left = n
} else {
this.left.addNode(n)
}
} else if (n.value > this.value) {
if (this.right == null) {
this.right = n;
this.right = n
} else {
this.right.addNode(n);
this.right.addNode(n)
}
}
};
}
// returns the constructor
return Node;
}());
return Node
}())
// class Tree
var Tree = (function () {
function Tree() {
function Tree () {
// Just store the root
this.root = null;
this.root = null
};
// Inorder traversal
Tree.prototype.traverse = function () {
this.root.visit();
};
this.root.visit()
}
// Start by searching the root
Tree.prototype.search = function (val) {
let found = this.root.search(val);
const found = this.root.search(val)
if (found === null) {
console.log(val + " not found");
console.log(val + ' not found')
} else {
console.log('Found:' + found.value)
}
else {
console.log("Found:" + found.value);
}
};
}
// Add a new value to the tree
Tree.prototype.addValue = function (val) {
let n = new Node(val);
const n = new Node(val)
if (this.root == null) {
this.root = n;
this.root = n
} else {
this.root.addNode(n);
this.root.addNode(n)
}
};
}
// returns the constructor
return Tree;
}());
return Tree
}())
//Implementation of BST
var bst = new Tree();
bst.addValue(6);
bst.addValue(3);
bst.addValue(9);
bst.addValue(2);
bst.addValue(8);
bst.addValue(4);
bst.traverse();
bst.search(8);
// Implementation of BST
var bst = new Tree()
bst.addValue(6)
bst.addValue(3)
bst.addValue(9)
bst.addValue(2)
bst.addValue(8)
bst.addValue(4)
bst.traverse()
bst.search(8)