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

Tell me what should be done in the base case for this recursive problem?

491


To describe the Complexity of Binary search, Quicksort and various other sorting and searching techniques..

568


What is the complexity of sorting algorithm?

501


What is heap with example?

523


Differentiate between arraylist and vector.

855






What is stable sort?

520


What is a undirected graph?

571


Is list an array?

444


Define adjacent nodes?

563


Can we change load factor of hashmap?

486


What does the term sorting refer to?

580


How to show internal storage representation of data structure in RDBM?

543


Which is faster list or set?

482


Can we declare array size as a negative number?

615


What do you know about the big-o notation and can you give some examples with respect to different data structures?

495