Computers and Technology

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
}
}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:30, miguel3maroghi
This technology is used to produce high-quality documents that look good on the computer screen and in print. wiki presentation paint desktop publishing
Answers: 3
image
Computers and Technology, 22.06.2019 19:00, dadonelson2109
If your accelerator suddenly gets stuck what should you do
Answers: 2
image
Computers and Technology, 22.06.2019 21:30, GamerGirl15
This graph compares the total cost of attending educational institutions in texas. the graph demonstrates that the cost at private and public technical schools greatly varies.
Answers: 2
image
Computers and Technology, 24.06.2019 00:30, petergriffin6772
Which boolean operator enables you to exclude a search term? a} not b} and c} or d} plus
Answers: 1
Do you know the correct answer?
Postfix evaluation In this assignment, you are to input an infix expression, convert it to
po...

Questions in other subjects:

Konu
Mathematics, 29.06.2019 02:00
Konu
Social Studies, 29.06.2019 02:00
Konu
Mathematics, 29.06.2019 02:00