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,
@bhaskar himanshu :- can u please explain ur algo for a * ( b + ( ( c - d
) / e ) )
On Sat, Jun 30, 2012 at 11:50 AM, himanshu kansal
himanshukansal...@gmail.com wrote:
i think this algo will do...
reverse the given prefix expression
while(!nd of input)
{ if it is operand
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]))
{
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
I think just reversing the prefix notation converts it to postfix notation
On Fri, Jun 29, 2012 at 7:46 PM, Gobind Kumar Hembram
gobind@gmail.comwrote:
Given an integer expression in a prefix format (i.e. the operator
precedes the number it is operating on) , print the expression in the
@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)
oh bhai mere. kewal preorder use karke kaise tree bana dega???
On Fri, Jun 29, 2012 at 11:23 PM, amrit harry dabbcomput...@gmail.comwrote:
@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
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
thishttp://www.velocityreviews.com/forums/t445633-prefix-to-infix-conversion.html
algo
to perform this.Then do the same for infix to postfix.It works
reverse the prefix notation and then reverse each continuous occurence of
operands
On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma abhi120...@gmail.comwrote:
convert prefix to infix,then convert infix to postfix.Now, to convert
prefix to infix, push numbers in one stack and operators in
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
bhaskar.kushwaha2...@gmail.com wrote:
reverse the prefix notation and then reverse each continuous occurence of
operands
On Sat, Jun 30, 2012 at 12:50 AM, Abhishek Sharma
Given an array containing sequence of bits (0 or 1), you have to sort
this array in the ascending order i.e. all 0' in first part of array
followed by all 1's. The constraints is that you can swap only the
adjacent elements in the array. Find the minimum number of swaps
required to sort the
Let u and r be the distance to move in the up and right directions. u=y2-y1
and r=x2-x1.
We have to move a total of u+r units. So the answer would be (u+r)!/u!r!
since we are counting only the distinct paths.
Each path from (x1,y1) to (x2,y2) may be expressed as a sequence of u+r
steps
Use a merge sort like procedure to count the number of inversions such that
0 appears after 1.
On Sat, Jun 23, 2012 at 11:34 AM, Gobind Kumar Hembram gobind@gmail.com
wrote:
Given an array containing sequence of bits (0 or 1), you have to sort
this array in the ascending order i.e. all 0'
If we use merge sort like procedure,ans will be 1 here it should be
3.we have to swap 0s and 1s linearly.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this
We need to sort as we count the inversions.
On Sat, Jun 23, 2012 at 11:56 AM, Gobind Kumar Hembram gobind@gmail.com
wrote:
If we use merge sort like procedure,ans will be 1 here it should be
3.we have to swap 0s and 1s linearly.
--
You received this message because you are subscribed
bcaz choosing any vertical will automatically fix the horizontals and
vice verse
(u+r) C r= (u+r) C u
On Sat, Jun 23, 2012 at 1:08 PM, Kumar Vishal kumar...@gmail.com wrote:
Let u and r be the distance to move in the up and right directions.
u=y2-y1 and r=x2-x1.
(u+r) C r
On
Let u and r be the distance to move in the up and right directions.
u=y2-y1 and r=x2-x1.
(u+r)Cr
On Sat, Jun 23, 2012 at 11:40 AM, Guruprasad Sridharan
sridharan.mi...@gmail.com wrote:
Let u and r be the distance to move in the up and right directions.
u=y2-y1 and r=x2-x1.
We have to
Given two positions in a 2-D matrix, say (x1, y1) and (x2, y2) where
x2=x1 and y2=y1. Find the total number of distinct paths between
(x1, y1) and (x2, y2). You can only move in right direction i.e.
positive x direction (+1, 0) or in up direction i.e. positive y
direction (0, +1) from any given
18 matches
Mail list logo