Evaluate the following prefix expression " ++ 26 + - 1324"
Answer Posted / navneet kang
++26 + -1324
METHOD:-
Start scanning the string from the right one character at a time.
If it is an operand, push it in stack.
If it is an operator, pop opnd1, opnd2 and perform the operation, specified by the operator. Push the result in the stack.
Repeat these steps until arr of input prefix strings ends.
Solution
1)Push 4,2,13 in stack one by one
2) - operator encountered
3)Take out 13 and 2 from stack and perform operation
4)Now Stack consist of 4,11
5)+ operator encountered
6)Now Stack consist of 15
7)Now push 6 in stack,Hence Now Stack consist of 15,6,2
8)Perform add operation + encountered
9)Now Stack consist of 15,8
10)+ operator encountered
11)Now Stack consist of 23
Hence Answer is 23
| Is This Answer Correct ? | 8 Yes | 3 No |
Post New Answer View All Answers
Define double hashing?
Which language is best to learn data structures?
What are the goals of data structure?
What is the use of substring?
What do you mean by tree edge?
Which is the best book for data structures and algorithms?
What is linked list ?
Is arraylist synchronized?
How do you find the number of comparisons in bubble sort?
How memory is reserved using a declaration statement in data structure?
What is difference between tree and binary tree?
Is pointer a variable in data structure?
Why would we use dynamically allocated arrays vs vectors?
What is sorted map?
What is the default capacity of hashmap?