Evaluate the following prefix expression " ++ 26 + - 1324"

Answer Posted / narayan kunal

for evaluating the prefix expression first reverse the
prefix expression then sole like postfix expression
the reverse of given expression is
4231-+62++
then push 4,2,3,1 to stack ,now pop last two elements and
1-3=-2
now again push -2 to stack,now the element of stack is 4,2
,-2 again pop last two elements and do
-2+2=0
we know that if zero comes like symbol then we directly pop
this and proceed to next step
now the content of stack is 4 lets go to the next step
push 6 and 2 to the stack so now content of stack is 4,6,2
now
pop last two elements
6+2=8
push 8 to stack
content of stack is 4,8
again remove last two elements of elements and do
4+8=12
now all operator and operand ends up
so final answer is 12

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define ancestor and descendant ?

553


How would you check if a binary tree is BST or not ? Write a program.

514


What is height balanced tree?

506


How is the front of the queue calculated in data structure?

439


What are the Differences between map and hashmap?

513






What are the scenarios in which an element can be inserted into the circular queue?

901


Is json a data structure?

525


What is an example of an array?

557


What does sorting an array do?

517


Explain binary searching and Fibinocci search?

565


Can you please explain the difference between string and an array?

519


Which list does not allow duplicates?

509


Will arraylist maintain insertion order?

503


Why do we use sorting?

480


How is heap sort implemented?

480