<!-- Program 12 works to manually solve a given expression by manually setting up the equation-->
<!-- This HTML code creates the heading, text boxs for the input, as well as the button for begining the solving of the expression -->
<h2>
Assignment 12, Binary Expression
</h2>
<H3>
Programmed By: Daniel Eberhart
</H3>
Solve the given expression 3(x+5y)
<br>
</br>
Keep in mind, the values must be numeric, not alpha.
<br>
</br>
<br>
Your first input value (X): <input id="x"/>
<br/>
Your second input value (Y): <input id="y"/>
<br>
<button onclick='start()'>Solve!</button>
<br>
<br>
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
<div id='output'></div>
<div id="4"></div>
JavaScript
function Nodee(content){
this.content = content;
this.next = null;
}
function Stack(){
this.head = null;
this._length = 0;
}
//Calculatiom
Stack.prototype.push = function(content) {
var nodee = new Nodee(content);
if (!this.head) {
this.head = nodee;
} else {
nodee.next = this.head;
this.head = nodee;
}//Set the head
this._length++;
}
//Begin the "pop function, as well as the shift
Stack.prototype.pop = function(c) {
var count = 2;
while (count > 0) {
this._length--;
this.head = this.head.next;
count--;
}
stack.push(c);
return document.getElementById("4").innerHTML = c;
}
Stack.prototype.print = function() {
var string = ' ';
var current = this.head;
while (current) {
string += current.content + "<br>";
current = current.next;
}
document.getElementById('4').innerHTML = string;
}
var stack = new Stack();//declare object
Stack.prototype.isValid = function(value) {
if (value == "+" || value == "-" || value == "/" || value == "*") {
stack.operateMe(value);
} else if (Number(parseFloat(value))==value) {
stack.push(value);
stack.print();
}//ensures that the value is numeric and adds
}
Stack.prototype.operateMe = function(value) {
var length = this._length;
if (length < 1) {
alert ("first two must be numbers");
} else {
var c = value;
var current = this.head;
var current1 = current.next;
var d = current.content;//get head for operation
var e = current1.content;//get head.next (second to last entry) for operation
switch (c) {
case '-':
c = parseInt(e - d);
break;
case '+':
c = parseInt(+e + + d);
break;
case '*':
c = parseInt(e * d);
break;
case '/':
c = parseFloat(e / d);
}
stack.pop(c);
}
}
var Node = function(v) {
this.value = v;
this.left = null;
this.right = null;
}
var BinaryTree = function() {
this.root = null;
}
var store...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.