vabhdman
BAN USERc=((a)+(b)*(a*b-a))-((b-a*a)*(b)+(a));
c =((2)+(3)*(2*3-2))-((3-2*2)*(3)+(2))
c=((2)+(3)*(4))-((-1)*(3)+(2))
c=((2)+12)-(-3+(2))
c=14-(-1)=15
SUM(X,Y) (X*Y) just means (x*y) and that is why the difference when applied by reverse, there are no brackets for x and y like ((x)*(y)) and MULT(X,Y) (X)+(Y) just adds x and y after calculating them. You should know that macro only replaces the code with the thing we tell it to replace it with. Its not a function which will calculate a value and return a solution which will takes its place. So simply replace your code with what is written in the macro exactly and the calculate
@Praveen Well the company doesn't matter, but this isn't just about pointer manipulation, what if the 0's 1's and 2's are just some key and list has more data and need to be sorted in order. The above mentioned technique is unstable. Most sorting's require that the algorithm should be stable(i.e. it should maintain order of equal elements).
- vabhdman September 12, 2012I think this problem can be thought of more easily if we don'd consider the link list elements containing 2, we can go through the link list once for just taking all the 1's are keeping them at the end of the list and then we can go again and keep all the 2's. Asymptotically this will take O(n) time only. Okay so we take a pointer first_encounter, we will set first_encounter to the element just before we encounter the first 1. Now we keep traversing the list. For ex
0->0->0->0->1->2->0>1->1
So first_encounter will be set at 4th position (as there is a 1 at 5th), now whenever we get anything but 1 in the next element we will splice it out and place it between first_encounter and its next element (which contains the first 1). for ex after reaching 2 list would look like
0->0->0->0->2->1->0->1->1
In the end you will get a list will all 1's in the end. Go through the list one more for 2's. With a little modification you can do this in one pass by using a second_encounter for 2's. You would just have put second_encounter at the end of all 1's (probably need a 3rd pointer for that).
I think this problem can be solved if we have a tree where no vertice has more than two edges, something like a link list perhaps. But a for a general tree it would depend on the kind of way the tree's edges and vertices are spread out. I can't be sure about it though. Please help if anyone ha a better answer
- vabhdman September 12, 2012
Hey here is a simple code in c/c++, m and n represent no. of rows and columns,
there are four conditions inside the second loop which cover all four boundary we have to traverse each time.
- vabhdman September 28, 2012