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

  Computing hash value for message

For a message, he computes the hash value H = (VChar 1 x VChar 2 x VChar 3 ...x VChar N) mod(26).

  Users and it organizations arm against phishing attacks

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

  Algorithm on dynamic programming-minimize amount of walking

Our goal is to plan this trip so that we minimize the maximum amount of walking done in a single day. Your algorithm should be based on dynamic programming and run efficiently.

  Process of insertion into a heap-implemented priority queue

Explain the process of insertion into a heap-implemented priority queue, and informally explain its complexity and the process of removal from a heap-implemented priority queue, and informally explain its complexity.

  Demonstrate a decision tree or table

Demonstrate a decision tree or table

  Different applications of data structure

What are the different applications of Data Structure

  Explaining augmented red-black tree

Consider T be augmented red-black tree, where each node x has attribute x.size, which is number of internal nodes in subtree rooted at x. Given such augmented red-black tree T.

  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.

  Write down the algorithm to insert an item

Write down the sample code to create a Linked List and allocate storage space for a node Write down the algorithm to insert an item At the beginning of a linked list

  Explaining view of header and footer areas of worksheet

In which view can you see header and footer areas of worksheet?

  Calculate worst-case run-time complexity of algorithm

Calculate the worst-case run-time complexity of your algorithm and prove optimality of the solution it gives. Suppose that the road is a straight line with a western end and an eastern end.

  Explaining use of encryption-virus and vpn

Write down the suitable example of best use of Encryption, Virus, VPN, Firewall securities, when and explain why?

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