Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Why can I not enter operand into the input box so that the last two numbers in the stack get added, subtracted, divided, or multiplied
Why can I not enter operand into the input box so that the last two numbers in the stack get added, subtracted, divided, or multiplied by their respective operands Also combine the push to stack function and evaluate function into one function. I will thumbs up if the code works!
RPN Calculator
class Node
constructordata
this.data data;
this.next null;
class Stack
constructor
this.top null;
pushdata
const newNode new Nodedata;
newNode.next this.top;
this.top newNode;
this.display;
pop
if this.top
this.displayOutputStack is empty";
return null;
const poppedData this.top.data;
this.top this.top.next;
this.display;
return poppedData;
display
let current this.top;
const stackContents ;
while current
stackContents.pushcurrentdata;
current current.next;
this.displayOutputContents of Stack: stackContents.join;
displayOutputmessage
document.getElementByIdstackOutputinnerText message;
const stack new Stack;
function pushToStack
const input document.getElementByIdstackInputvalue;
if isNaNinput
stack.pushparseFloatinput;
else
stack.displayOutputInvalid input: Please enter a number";
document.getElementByIdstackInputvalue ; Clear the input box after push
function evaluate
const input document.getElementByIdstackInputvalue;
let result;
if includesinput
const operand stack.pop;
const operand stack.pop;
if operand null && operand null
switchinput
case :
result operand operand;
break;
case :
result operand operand;
break;
case :
result operand operand;
break;
case :
if operand
stack.displayOutputError: Division by zero";
return;
result operand operand;
break;
stack.pushresult;
else
stack.displayOutputError: Not enough operands";
else
stack.displayOutputInvalid operator: Please enter or ;
document.getElementByIdstackInputvalue ; Clear the input box after evaluation
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started