Created
May 2, 2016 16:56
-
-
Save phedoreanu/3bf8e105b4746f932be123db45ae8567 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func xorSwap(x, y *int) { | |
| if x != y { | |
| *x ^= *y; | |
| *y ^= *x; | |
| *x ^= *y; | |
| } | |
| } | |
| func main() { | |
| x, y := 1, 0 | |
| fmt.Println(x, y) | |
| xorSwap(&x, &y) | |
| fmt.Println(x, y) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.golang.org/p/MOauP5RRMg