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 ? | 7 Yes | 3 No |
Post New Answer View All Answers
Which is faster hashmap or hashset?
Is a hash table a map?
write a code for Implementation of stack and queues.
How do you find the length of an arraylist?
If you are given a choice to use either arraylist and linkedlist, which one would you use and why?
For the following COBOL code, draw the Binary tree? 01 STUDENT_REC. 02 NAME. 03 FIRST_NAME PIC X(10). 03 LAST_NAME PIC X(10). 02 YEAR_OF_STUDY. 03 FIRST_SEM PIC XX. 03 SECOND_SEM PIC XX.
what is the difference between dynamic as well as non - dynamic data structures.
What is a bubble sort and how do you perform it?
Does treemap preserve order?
State the advantages of using infix notations?
What is dynamic array in excel?
Can we put null key in hashmap?
What are the different types of collections?
Explain stacks and queues in detail.
Define separate chaining?