Will this work ?
consider A+(B*C)
have an operator stack to hold the operators. As we scan elements from left
to right,push the operators in operator stack.
when you encounter a '(' , then scan to find the first operator that comes
after '(' (in this case *).
If this operator has a higher precedence than the operator @ top of stack
(in this case +). Then we can safely remove the parenthesis. Else we cant
remove the brackets
On Thu, Jun 3, 2010 at 1:05 PM, divya jain <[email protected]> wrote:
>
>
> 1.calculte the postfix of given expression.
> 2.now remove a particular parenthesis from expression and check if the
> postfix of this expression is equal to the postfix of original expression.
> if yes then the parenthesis we have removed were extra. if no then the
> parenthesis were not exta.
> 3 now remove other parenthesis as step 2 and repeat till u have done this
> for all parenthesis
>
> On 1 June 2010 20:12, Raj N <[email protected]> wrote:
>
>> How to remove extra parentheses in an infix string. For example if it
>> is A+(B*C) parentheses for * is not required as it has higher
>> precedence. Can someone suggest a good routine for this?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.