just a small doubt..... if x=10 and y=20 thn wht wud b the value of (x ^ y)? acc to me....it 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 <[email protected]> wrote: > @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 > when u pass the same index values... > Conclusion: Either code as given in above Q or use the temporary > var... > > -- > 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.
