Postfix evaluation
In this assignment, you are to input an infix expression, convert it to
po...
![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 19.03.2021 16:00 987654321156
Postfix evaluation
In this assignment, you are to input an infix expression, convert it to
postfix (see the previous assignment - Posted below) and then evaluate it. You should
use a generic stack(i. e. a templated stack). Note: Ignore blank lines.
Input for the assignment:
2 + 3 * 5
2 + 3 * 5 ^ 6
2 + 3 - 5 + 6 - 4 + 2 - 1
2 + 3 * (5 - 6) - 4
2 * 3 ^ 5 * 6 - 4
(2 + 3) * 6 ^ 2
Sample output
1: 2 + 3 * 5
235*+
17
2: 2 + 3 * 5 ^ 6
2356^*+
46877
3: 2 + 3 - 5 + 6 - 4 + 2 - 1
23+5-6+4-2+1-
3
4: 2 + 3 * (5 - 6) - 4
2356-*+4-
-5
5: 2 * 3 ^ 5 * 6 - 4
235^*6*4-
2912
6: (2 + 3) * 6 ^ 2
23+62^*
180
You might also try:
7: ( ( ( ( 2 + 3 - 4 ) / 2 + 8 ) * 3 * ( 4 + 5 ) / 2 / 3 + 9 ) )
23+4-2/8+3*45+*2/3/9+
45
The Evaluation algorithm is as follows:
st = postfix_string
for (i=0; i < length(st); i++)
{
token = st[i]
switch (token)
{
digit :
push token
break
operator :
pop opn2
pop opn1
result = evaluate(opn1, token, opn2)
push result
break
}
}
![ansver](/tpl/images/cats/User.png)
Answers: 2
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Other questions on the subject: Computers and Technology
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 06:30, westjayson69
Requirement types discussed during software development include functional and color scheme nonfunctional and code style constraint and nonfunctional fashionable and functional.
Answers: 2
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 14:30, SKYBLUE1015
What percentage of companies is projected to use social media to locate new employees in 2012
Answers: 2
![image](/tpl/images/cats/informatica.png)
You know the right answer?
Questions in other subjects:
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/informatica.png)
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/ekonomika.png)
![Konu](/tpl/images/cats/fizika.png)
![Konu](/tpl/images/cats/ekonomika.png)
![Konu](/tpl/images/cats/ekonomika.png)
![Konu](/tpl/images/cats/obshestvoznanie.png)
![Konu](/tpl/images/cats/mat.png)