Computing suffix expression of Data Structure Stack

Source: Internet
Author: User

For a given suffix expression (assuming it is valid)

Note: The secondary algorithm is based on the basic operator of the binary operator and the operand is a positive integer!

The basic idea of its evaluation is: to traverse a given expression, if an operand is encountered, it will be pushed into the stack; If an operator is encountered, two elements at the top of the stack will pop up, assume that the two elements at the top of the stack Are A and B (A is at the bottom of B), and apply the operator to these two elements at the top of the stack, such as B-.(Note that B is on the left a and on the right)Then press the calculation result into the stack (used to act as the operand of the next operator );

The final output stack top element is the result (in fact, if the expression is valid, there will be only one element in the stack)

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.