Swapping two Numbers without Temporary Variables
1–10 of 93 posts
Re: Swapping two Numbers without Temporary Variables
#2Re: Swapping two Numbers without Temporary Variables
#3Re: Swapping two Numbers without Temporary Variables
#4This is a variation on xor-swap, but one that suffers from over(/under)flow https://en.wikipedia.org/wiki/XOR_swap_algorithm#Variations
Re: Swapping two Numbers without Temporary Variables
#5 a, b = b, a
Or Rust: (a, b) = (b, a);Re: Swapping two Numbers without Temporary Variables
#6Or, in Python a, b = b, a Or Rust: (a, b) = (b, a);
Re: Swapping two Numbers without Temporary Variables
#7Or, in Python a, b = b, a Or Rust: (a, b) = (b, a);
Re: Swapping two Numbers without Temporary Variables
#8Re: Swapping two Numbers without Temporary Variables
#9This is a variation on xor-swap, but one that suffers from over(/under)flow https://en.wikipedia.org/wiki/XOR_swap_algorithm#Variations
The classic use of XOR-swap was to traverse a tree without needing a stack. As you traverse the tree, the forward links are swapped with backward links, so you can find your way back. Used in the mark phase of some early garbage collectors.
Re: Swapping two Numbers without Temporary Variables
#10This is a variation on xor-swap, but one that suffers from over(/under)flow https://en.wikipedia.org/wiki/XOR_swap_algorithm#Variations
The classic use of XOR-swap was to traverse a tree without needing a stack. As you traverse the tree, the forward links are swapped with backward links, so you can find your way back. Used in the mark phase of some early garbage collectors.