*Sigh*
On Nov 19, 6:24 am, Gaurav Gulzar wrote:
> one liner
> a^=b^=a^=b
>
> On Mon, Nov 19, 2012 at 4:30 PM, abhinav gupta wrote:
>
>
>
>
>
>
>
> > we need to use + and - as operator overloading. so, that i will work f9
> > for ur objects.
>
> > so make operator overloading for + and - opera
one liner
a^=b^=a^=b
On Mon, Nov 19, 2012 at 4:30 PM, abhinav gupta wrote:
> we need to use + and - as operator overloading. so, that i will work f9
> for ur objects.
>
> so make operator overloading for + and - operator.
>
>
> On Sat, Nov 17, 2012 at 9:12 PM, AISHWARYA KUMAR wrote:
>
>
we need to use + and - as operator overloading. so, that i will work f9 for
ur objects.
so make operator overloading for + and - operator.
On Sat, Nov 17, 2012 at 9:12 PM, AISHWARYA KUMAR wrote:
>
> in one line
> a=a^b^(b=a) ;
>
> --
>
>
>
--
*Thanks and Regards,*
Ab
in one line
a=a^b^(b=a) ;
--
That's right!
On Monday, November 5, 2012 2:02:43 AM UTC+5:30, manish wrote:
>
> Swapping two objects (not integers/chars),without using temp...?
> my solution is using xor operation..is that right and ny other solutions ?
--
You received this message because you are subscribed to the Google Gro
Can anyone please help me to understand (with example) that how those
solutions work, if they are OBJECTS?
On Sunday, November 4, 2012 3:32:43 PM UTC-5, manish wrote:
>
> Swapping two objects (not integers/chars),without using temp...?
> my solution is using xor operation..is that right and ny ot
@Don: This can be easily fixed, as there is no need to swap equal values,
so:
void swap(int &a, int &b)
{
if( a != b )
{
a ^= b;
b ^= a;
a ^= b;
}
}
On Monday, November 5, 2012 10:41:42 AM UTC-6, Don wrote:
> Note that most of these methods fail if you try t
Dave is right. The code is undefined, which means that a valid
compiler could produce code which makes monkeys fly out of your nose.
On Nov 13, 12:38 am, Dave wrote:
> @Shivam: Your one-line "solution" violates the sequence point rule. Hence,
> it is non-standard, and the result is compiler depen
But how is that going to work for objects?
On Mon, Nov 5, 2012 at 6:43 AM, Ashok Varma wrote:
> Try this: a = a + b - (b = a); //single line code to swap
>
>
>
>
> On Mon, Nov 5, 2012 at 4:53 AM, Dave wrote:
>
>> @Manish: Sure.
>>
>> a = a + b;
>> b = a - b;
>> a = a - b;
>>
>> In 2-s complemen
Note that most of these methods fail if you try to swap an item with
itself.
For example, swap(a[i], a[j]) will fail if i==j and swap is
implemented as
void swap(int &a, int&b)
{
a ^= b;
b ^= a;
a ^= b;
}
Don
On Nov 4, 3:32 pm, manish wrote:
> Swapping two objects (not integers/chars)
Try this: a = a + b - (b = a); //single line code to swap
On Mon, Nov 5, 2012 at 4:53 AM, Dave wrote:
> @Manish: Sure.
>
> a = a + b;
> b = a - b;
> a = a - b;
>
> In 2-s complement arithmetic, it works even if a + b overflows.
>
> Dave
>
> On Sunday, November 4, 2012 2:32:43 PM UTC-6, manish
@Manish: Sure.
a = a + b;
b = a - b;
a = a - b;
In 2-s complement arithmetic, it works even if a + b overflows.
Dave
On Sunday, November 4, 2012 2:32:43 PM UTC-6, manish wrote:
> Swapping two objects (not integers/chars),without using temp...?
> my solution is using xor operation..is tha
12 matches
Mail list logo