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


Please Help Members By Posting Answers For Below Questions

Which is faster hashmap or hashset?

466


Is a hash table a map?

481


write a code for Implementation of stack and queues.

520


How do you find the length of an arraylist?

484


If you are given a choice to use either arraylist and linkedlist, which one would you use and why?

496






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.

771


what is the difference between dynamic as well as non - dynamic data structures.

516


What is a bubble sort and how do you perform it?

653


Does treemap preserve order?

463


State the advantages of using infix notations?

670


What is dynamic array in excel?

454


Can we put null key in hashmap?

481


What are the different types of collections?

492


Explain stacks and queues in detail.

646


Define separate chaining?

539