Implement algorithm for evaluation of arithmetic expression

Assignment Help Data Structure & Algorithms
Reference no: EM1358023

Implement the following algorithm for the evaluation of arithmetic expressions. Each operator has a precedence. The + and - operators have the lowest precedence, * and / have higher (and equal) precedence, and ^ (which denotes "raising to a power" in this excercise) has the highest. For example,

3 * 4 ^ 2 + 5

should mean the same thing as

(3 * (4 ^ 2)) + 5

with a value of 53.

in your algorithm, use two stacks. One stack holds numbers, the other holds operators. When you encounter a number, push it on the number stack. When you encounter an operator, push it on the operator stack if it has higher precedence than the operator on top of the stack. Otherwise, pop an operator off the operator stack, pop two numbers off the number stack, and push the result of the computation on the number stack. Repeat until the top of the operator stack has lower precedence. At the end of the expression, clear the stack in the same way.

Reference no: EM1358023

Questions Cloud

Physical units-nrv-constant : Bubble Corporation manufactures two products, I and II, from a joint process. A single production costs $4,000 and results in 100 units of I and 400 units of II. To be ready for sale, both products must be processed further, incurring separable co..
Verbally aggressive schizophrenic client : Sometimes I am able to, and at other times I can't even get him to listen to me. Do you have any suggestions on how I can help him when he has those episodes?
Compute the confidence intervals for the expected annual : Using the following table, compute the 95% confidence intervals for the expected annual return of the four different investments.
Enticing non-union organizations to unionize : Explain what are the various methods utilized by staff representatives to woo the employees of non-union organizations to unionize?
Implement algorithm for evaluation of arithmetic expression : Implement the following algorithm for the evaluation of arithmetic expressions. Each operator has a precedence. The + and - operators have the lowest precedence.
Find the eight balls speed after the colision : Find the eight ball's speed after the colision. Parallel rays of green mercury light with a wavelength of 546 nm pass through a slit with a width of 0.437 mm. What is distance from the central maximum to the first minimum on a screen 1.75 mm away f..
Determine the equilibrium market value : Jason Corporation had after-tax income of $15,000 with 10,000 stock shares outstanding. The 2 owners are trying to determine the equilibrium market value for the stock prior to going public.
Recruitment and retention-hiring strategies : Recruitment and Retention: Hiring Strategies - The original case study
What is the market value of this patent : Assume a firm has a patent on one of its products whose sale generates $32,700/year more revenue than production costs. If the annual interest rate is 20 percent, what is the market value of this patent.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design algorithm determining annual profit for company

Your goal is to solve the following simple programming exercise. You have been asked by your accounting department to design an algorithm determining the annual profit for your company.

  Find fraction of time during which queue grows

Suppose now there are three users. Find the probability that at a given time, all three users are transmitting simultaneously. Find the fraction of time during which the queue grows.

  Data structures and algorithm design

Data Structures and Algorithm Design

  Factors-principles considering indecency regulation issues

What factors and principles should the federal government take into account when considering indecency regulation issues?

  Computing total number of keys needed in symmetric cipher

Determine the total number of keys that are needed for organization if symmetric cipher is used.

  Explain algorithm which gives initial infection of computer

Explain an O(m+n) algorithm which, given an initial infection of a computer Ca at time t determines for each other computer the earliest time at which it can become infected.

  Creating financial tracking program

Acme Inc. is making next generation financial tracking program, and Alice has been provided the task of writing encryption component.

  Explaining instruction format of operation code field

Operation code field, a mode field, to specify one of seven addressing modes, a register address field to specify one of 60 processor registers, and memory address. Specify instruction format and number of bits in each field if the instruction ..

  Users and it organizations arm against phishing attacks

How users and IT organizations must arm themselves against these attacks?

  Determine the branching factor

Expalin the search algorithm that results from each of the following special cases. How does it relate to other algorithms we have discussed.

  Explain solution to recurrence-appealing to recursion tree

Solve the following recurrence relations by the method of your choiceT(n) = 1 for n = 4 and T(n) =pnT(pn) + n for n > 4. Argue that the solution to the recurrence T(n) = T(n=3) + T(2n=3) + cn is (n lg n) by appealing to the recursion tree.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd