When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
83 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
@swift vessel it's not really helpful to do people's assignment for them
@fluid salmon It was very simple question that's why i choose to answer it
not simple when you don't understand it
it's also technically against the rules
#rules 5. We're happy to help you learn, however, we do not condone academic dishonesty. We will not take your tests for you or write programs for you. Likewise avoid giving full solutions to problems when helping other members.
Sorry i have deleted it
@ocean sequoia what have you tried so far?
yea i have tried
but it is kind of weird
this is wat i got
I think that looks correct
actually it is wrong
This is wrong because your division should be performed at last
So division operator should come first and then multiplication
if i change that infix to postfix i will get 3 4 + 5 2 - * 6 1 + /
and how can i reverse that to get prefix
@ocean sequoia We cannot obtain prefix by reversing postfix expression
Just think logically
i am writing this code
On internet, most people will do like reverse infix then postfix then reversed postfix to get prefix
@ocean sequoia Ohh you want to code it , i thought you are just converting it manually
Then you will first have to reverse the expression , convert it to postfix and then reverse it again
this is wat i do
reverse
postfix
reverse
The problem is occurring because of associativity rules
When you reverse the expression at first stage, the order of operators with similar precedence also reverses
In your case '/' comes left side and '*' goes right side, but here * should evaluate first because in original expression * was left side
So, whenever you are converting reversed expression into postfix, you should not pop out operators with similar precedence
So, your postfix should be like this :
16+25-43+*/
@ocean sequoia You got my point?
yea i got it
great lmk if you have any other doubts with this
So i got this problem
Infix : 59+ 107 * 83 7291 / ( 27 - ( 112 * 153 ) * ( 111 + 76 ) )
Reverse : ( ( ( 67 + 111 ) * ( 351 * 211 ) - 72 ) / 19 * 27 * 38 * 701 + 95 )
postfix: 67 111 + 351 211 * * 72 - 19 27 38 701 * * 95 + * /
Reverse postfix: / * + 59 * * 107 83 72 91 - 27 * * 112 153 + 111 76 (This is wat i got)
Prefix(Answer) : + 59 / * * * 107 83 72 91 - 27 * * 112 153 + 111 76
@ocean sequoia Can you clearly show me what is the infix expression? because i can't see multiplication operators in your infix expression, but i can see them in postfix expression
Ok i think you have wrote it ,but it is not visible to me
59+ 107 * 83 *72 *91 / ( 27 - ( 112 * 153 ) * ( 111 + 76 ) )
Okk it is visible now
sorry
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
here my code
u can take a look at it
@ocean sequoia Yes sure
@ocean sequoia it's okay
@ocean sequoia Why are you reversing the numbers also
don't reverse the numbers , just reverse the expression
For example ,in reversed expression 76 should be 76 only
It will not be 67
Yeah I guess so, because you are again reversing the expression
yea
Your postfix of reverse expression is wrong though
Wait let me go through the code first
Your post fix of reverse expression should be: 67 111 + 351 211 * * 72 - 19 27 38 701 * * */ 95 +
Because when you reach at "+" , you will have to pop out '*' and append to the output
Because * have greater precedence than +
yea but with my code idk where to fix
let me check
@ocean sequoia Why are you checking if operator.top() is empty at line 75 and 116?
Ohh, i think some glitch, after copying it
@ocean sequoia It is very complex, but issue i can see is you don't have any loop inside the main loop, which means, whenever any lower precedence operator comes, it will not able to pop out all the operators with higher precedence from the stack
yea i also think like that
In this expression you have to pop out all * operator when + comes
You can try to make your code simpler, it will be easy to understand and debug for you also
My suggestion is, define one function which will deal with the precedence
for example: if( op=='^'){ return 3} if(op=='*){ return 2 } something like this
@ocean sequoia Has your question been resolved? If so, run !solved :)
not yet =))
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity