Created
November 16, 2012 12:18
-
-
Save javajawa/4086850 to your computer and use it in GitHub Desktop.
Swapping without extra variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample answer for a quiz :) | |
swap (int &a, int &b) | |
{ | |
a = a ^ b; // a' = a ^ b | |
b = a ^ b; // b' = a' ^ b = a ^ b ^ b = a | |
a = a ^ b; // a'' = a' ^ b' = a ^ b ^ a = b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment