in Programming in C
2,253 views
0 votes
0 votes

in Programming in C
2.3k views

4 Comments

MiNiPanda hmm now you got my point that i was saying 

0
0

 srestha no correct answer is -37 and which is solved as [2+{3- (6*7)}]

 

Because we don't only want to solve this  question but we also take care of the priority order of the OPRATORS

 

hope it helps give upvote

0
0
@Mini Panda

yes, I have done mistake:)
0
0

2 Answers

2 votes
2 votes

Given infix expression are$:2 + 3 - ( 6 * 7 ) $

now convert infix to postfix expression using operator stack, we get postfix expression$: 2 3 + 6 7 * - $ [Because, if associativity not given we take $'+' $ are left associative]

now postfix expression$: 2 3 + 6 7 * - $

Scan entire string from left to right, when any operator come, pop top two elements and perform an operation (let say result = pop2$+$po1) and then push back result into the stack. Repeat this step until string scanning is over. 

So,i got $(3)$ are stack configuration.

and if we take $'+'$  is right associative,then postfix expression are$: 2 3 6 7 * - + $  

So, I got $(2)$ are stack configuration.

 

edited by

4 Comments

Yes,thanks for correcting me
0
0
It's funny!! Option A is wrong just because there is 2 cm blank space in a stack??
0
0
Yeah,option $(1)$ can not be right.
0
0
0 votes
0 votes
I think it must be not possible stack configuration

 by taking * as high precedence , + and - have same precedence

now there are two cases it can be left as well as right so applying as left associative we get option 1 and 3 as we apply right associative we also get option 2

So option 4 must be wrong

3 Comments

option 1 cannot be the answer .. in stack 1st position cannot be empty earlier then the later elements in the stack... remember stack is LIFO ( Last In First Out)

And We are not taking the * is highest precedence and + & - have same precedence ,, It is a Rule 

1
1
sorry i didnt consider the first position .It just skipped ,

Agree Ist position of stack cannot be empty
1
1
then please upvoted the answer thanks for giving the chance to help you
0
0