Question
QUICK ANSWER PLS
What is the result of the following prefix expression? + 10 + 54
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :

EVALUATE_PREFIX(STRING)

Step 1: Start by picking up literals from the end

Step 2: If element is an operand push it to Stack

Step 3: If the element is an operator pop two elements from the Stack.

Operate on these elements according to the operator, and push the result  back to the Stack

Step 4: Move left and process elements as shown in step 2 and 3 until all are scanned in the expression.

Step 5: The Result is stored at the top of the Stack

Explanation :

+ 10 * 5 4

1. Push 4 to stack

2. Push 5 to stack. Stack contains

5

4

3. * is operator. Pop two elements, multiply and push to stack. Stack contains

20

4. Push 10 to stack. Stack contains

10

20

5. + is operator. Pop two elements, add and push to stack. Stack contains

30

6. Result is 30

Add a comment
Know the answer?
Add Answer to:
QUICK ANSWER PLS What is the result of the following prefix expression? + 10 + 54
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT