@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 to swap an item with
> itself. void swap(int &a, int&b)
> {
> a ^= b;
> b ^= a;
> a ^= b;
> }
>
>
> For example, swap(a[i], a[j]) will fail if i==j and swap is
> implemented as
>
>
> Don
>
> On Nov 4, 3:32 pm, manish <[email protected]> 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 Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/2QXdGv1P-iMJ.
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.