I think no need to reverse the string,following program is giving me
correct o/p.Although right now this program will work only for binary
operator,for unary add extra condition
main()
{
char str[100];
int i=0;
int digit;
scanf("%s",str);
while(str[i])
{
if(isdigit(str[i]))
{
printf("%c",str[i]);
if(isdigit(str[i+1]))
{
printf("%c",str[i+1]);
digit=popstack();
printf("%c",digit);
i++;
}
}
else if(str[i]>=33 && str[i]<=47)
{
pushstack(str[i]);
}
i++;
}
while(top!=0)
{
digit=popstack();
printf("%c",digit);
}
}
On Sat, Jun 30, 2012 at 11:50 AM, himanshu kansal <
[email protected]> wrote:
> i think this algo will do...
> reverse the given prefix expression
> while(!nd of input)
> { if it is operand
> push in a stack
> if its an operator
> { op1=pop(stack);
> op2=pop(stack);
> push (op1 op2 operator) on to stack;
>
> }
> }
> On Sat, Jun 30, 2012 at 1:56 AM, Bhaskar Kushwaha <
> [email protected]> wrote:
>
>> example
>> -+53+2/36
>> step 1: 63/2+35+-
>> step 2: 36/2+53+-
>>
>> On Sat, Jun 30, 2012 at 1:55 AM, Bhaskar Kushwaha <
>> [email protected]> wrote:
>>
>>> reverse the prefix notation and then reverse each continuous occurence
>>> of operands
>>>
>>>
>>> On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma
>>> <[email protected]>wrote:
>>>
>>>> convert prefix to infix,then convert infix to postfix.Now, to convert
>>>> prefix to infix, push numbers in one stack and operators in other.Then use
>>>> this<http://www.velocityreviews.com/forums/t445633-prefix-to-infix-conversion.html>
>>>> algo
>>>> to perform this.Then do the same for infix to postfix.It works with simple
>>>> operators,but difficult to implement with parenthesis.
>>>>
>>>>
>>>> On Sat, Jun 30, 2012 at 12:21 AM, rahul ranjan <
>>>> [email protected]> wrote:
>>>>
>>>>> oh bhai mere..... kewal preorder use karke kaise tree bana dega???
>>>>>
>>>>>
>>>>> On Fri, Jun 29, 2012 at 11:23 PM, amrit harry <[email protected]
>>>>> > wrote:
>>>>>
>>>>>> @bhaskar ur algo fails on this case (5+3)-(2+(3/6))
>>>>>> -+53+2/36
>>>>>> 63/2+35-+
>>>>>> showing that 6/3 but actually it is 3/6
>>>>>> so i think it could be done by folowing algo
>>>>>> make a binary tree of given expression in O(n) then do postorder
>>>>>> traversal take O(n) so problem can be solved in O(n). and take O(2*n+1)
>>>>>> space
>>>>>>
>>>>>> On Fri, Jun 29, 2012 at 9:13 PM, Bhaskar Kushwaha <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> I think just reversing the prefix notation converts it to postfix
>>>>>>> notation
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> Given an integer expression in a prefix format (i.e. the operator
>>>>>>>> precedes the number it is operating on) , print the expression in
>>>>>>>> the
>>>>>>>> post fix format .
>>>>>>>>
>>>>>>>> Example: If the integer expression is in the prefix format is
>>>>>>>> *+56-78,
>>>>>>>> the postfix format expression is 56+78-*. Both of these
>>>>>>>> correspond to the expression (5+6)*(7-8).
>>>>>>>>
>>>>>>>> --
>>>>>>>> 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.
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> regards,
>>>>>>> Bhaskar Kushwaha
>>>>>>> Student
>>>>>>> Final year
>>>>>>> CSE
>>>>>>> M.N.N.I.T. Allahabad
>>>>>>>
>>>>>>> --
>>>>>>> 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.
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Thanks & Regards
>>>>>> Amritpal singh
>>>>>>
>>>>>> --
>>>>>> 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.
>>>>>>
>>>>>
>>>>> --
>>>>> 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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Abhishek Sharma
>>>> Under-Graduate Student,
>>>> PEC University of Technology
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> regards,
>>> Bhaskar Kushwaha
>>> Student
>>> Final year
>>> CSE
>>> M.N.N.I.T. Allahabad
>>>
>>>
>>
>>
>> --
>> regards,
>> Bhaskar Kushwaha
>> Student
>> Final year
>> CSE
>> M.N.N.I.T. Allahabad
>>
>> --
>> 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.
>>
>
>
>
> --
>
> Regards
> Himanshu Kansal
> Msc Comp. sc.
> (University of Delhi)
>
>
> --
> 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.
>
--
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.