Question
Analyze the time complexity of this program in big-O notation, assuming that the total number of numbers and symbols in the expression is n. Expect
Analyze the time complexity of this program in big-O notation, assuming that the total number of numbers and symbols in the expression is n. Expect any type of numbers including integers, floats/doubles
static double evalPostFix() { Stack
Scanner sc = new Scanner(System.in); token = sc.next(); while (token.charAt(0) != '=') { try { isNumber = true; result = Double.parseDouble(token); } catch (Exception e) { isNumber = false; } if (isNumber) s.push(result); else { switch (token.charAt(0)) { case +: a = s.pop(); b = s.pop(); s.push(a+b); break; case -: a = s.pop(); b = s.pop(); s.push(a-b); break; case *: a = s.pop(); b = s.pop(); s.push(a*b); break; case /: a = s.pop(); b = s.pop(); s.push(a/b); break; case ^: a = s.pop(); b = s.pop(); s.push(Math.exp(a*Math.log(b))); break; } }
token = sc.next(); } return s.peek(); }
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