2008-10-24, 03:05 AM
Python:
Python (cheating method):
C:
Pascal:
Code:
def xorswap(a, b):
if(a != b):
a ^= b
b ^= a
a ^= b
return (a, b)Python (cheating method):
Code:
def swap(a, b):
a, b = b, a
return (a, b)C:
Code:
void xorswap(int *x, int *y)
{
if(x != y)
{
*x ^= *y
*y ^= *x
*x ^= *y
}
}Pascal:
Code:
procedure xorswap(var X, Y: integer);
begin
if X <> Y then begin
X := X xor Y;
Y := X xor Y;
X := X xor Y;
end
end