Java Codes by Gamer
Monday, September 06, 2004
 
Swapping Without a Temporary Location
We all know how to swap to numbers using a temporary location. Say two numbers are A, B
then to swap
C = new type;
C = A
A = B
B = C
Also this can be done in following way. It requires butwise XOR (^) operator to be working. For object and struct types one can apply ^ directly on bit level.
A = A ^ B
B = A ^ B
A = A ^ B
Swap without a temporary location!

Comments: Post a Comment

<< Home

Powered by Blogger