lab 12
by HSilvaDaytona
HTML
3*(x + 5*y)
<p />
<div class="main-container">
<div class="container" id="convert">
<form action="">
X:<br>
<input type="text" name="x" id="xVal">
<br> Y:
<br>
<input type="text" name="y" id="yVal">
</form>
<button id="convert">TREE BUTTON</button>
<p id="output"></p>
</div>
</div>
JavaScript
document.getElementById("convert").addEventListener("click", function() {
convert();
});
var node = {
value: 125,
left: null,
right: null
};
function BinarySearchTree() {
this._root = null;
}
BinarySearchTree.prototype = {
//restore constructor
constructor: BinarySearchTree,
add: function(value) {
//New object
var node = {
value: value,
left: null,
right: null
},
current;
if (this._root === null) {
this._root = node;
} else {
current = this._root;
while (true) {
if (value < current.value) {
if (current.left === null) {
current.left = node;
break;
} else {
current = current.left;
}
} else if (value > current.value) {
if (current.right === null) {
current.right = node;
break;
} else {
current = current.right;
}
} else {
break;
}
}
}
},
traverse: function(process) {
function postOrder(node) {
if (node) {
if (node.left !== null) {
postOrder(node.left);
}
if (node.right !== null) {
postOrder(node.right);
}
process.call(this, node);
}
}
postOrder(this._root);
},
toArray: function() {
var result = [];
this.traverse(function(node) {
result.push(node.value);
});
return result;
},
toString: function() {
return this.toArray().toString();
}
};
function convert(element) {
var x = document.getElementById("xVal").value;
var y = document.getElementById("yVal").value;
x = parseInt(x, 10);
y = parseInt(y, 10);
var out = 3 * (x + 5 * y);
//document.write('<div>Print this after the script tag</div>' y);
var docWrite = document.getElementById("output");
docWrite.innerHTML = out;
}