Re: [algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-13 Thread tech rascal
just a small doubt. if x=10 and y=20 thn wht wud b the value of (x ^ y)? acc to meit has to be 1 bt if the value is 1 , thn how wud the method using XOR operations work?.plz xplain On Mon, Jun 13, 2011 at 3:18 AM, KK kunalkapadi...@gmail.com wrote: @kunal Actually its not same

Re: [algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-13 Thread Felipe Ferreri Tonello
On 06/13/2011 05:22 PM, tech rascal wrote: just a small doubt. if x=10 and y=20 thn wht wud b the value of (x ^ y)? acc to meit has to be 1 bt if the value is 1 , thn how wud the method using XOR operations work?.plz xplain On Mon, Jun 13, 2011 at 3:18 AM, KK

[algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-12 Thread KK
@kunal Actually its not same value its the same variable and it arises only if u code the given way(and some people do it this way) void swap(int a, int b) { a ^= b ^= a ^= b; } now we have int a = 10; swap(a, a) This will set a's value to 0...and this happens while sorting arrays

[algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-11 Thread KK
It wont give correct answer when u pass same values of a and b and such conditions arises in sorting -- *** Kunal Kapadia Computer Science and Engineering B.Tech 2nd yr NIT Trichy *** -- You received this

[algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-11 Thread rohit
can u pls explain the overflow and underflow in +- approach On Jun 11, 8:58 am, Wladimir Tavares wladimir...@gmail.com wrote: Swapping two variables without using a temporary variable using the + and -: x = a; y = b; x = x + y / / x = a + b; y = x - y / / y = a + b-b = a; x = x - y / / x

[algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-11 Thread Andreas Hahn
Well, on pod, this is an alternative to swapping two variables with a third temporary, but be careful with objects! It won't work on all objects and in C++0x there is the move for this purpose. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-11 Thread nicks
Hers's another one line solution for swapping two variables a and b a=b+a-(b=a) On Sat, Jun 11, 2011 at 2:55 PM, Andreas Hahn www.gal...@googlemail.comwrote: Well, on pod, this is an alternative to swapping two variables with a third temporary, but be careful with objects! It won't work on