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
How can we reverse the order in the treemap?
Why it is said that searching a node in a binary search tree is efficient than that of a simple binary tree?
Describe full binary tree and complete binary tree.
Is array part of collection framework?
Differentiate file structure from storage structure?
What are the collision resolution methods?
Which sort algorithm is best?
Does concat mutate array?
List the data structures which are used in network data modal.
Is char array null terminated?
Which sorting algorithm is used in arrays sort?
How expression trees are gets represented in data structure?
Is unordered_map a hash table?
Why is it called bubble sort?
How do treesets work internally?