3 ms·
XOR swap, as others have noted, is another very common way of implementing a swap without temporary variables. It's also a good exercise for formal verificatio
by siraben 5y ago
XOR swap, as others have noted, is another very common way of implementing a swap without temporary variables. It's also a good exercise for formal verification, here's a proof in Coq of XOR swap's correctness in C.[0]
[0] https://gist.github.com/siraben/d2ad58914166d5f6139b03b1b503ed6c https://gist.github.com/siraben/d2ad58914166d5f6139b03b1b503...