![]() |
||||||||
|
|
Swapping 2 integers There are 3 ways to swap 2 integers, the most common one is to use temporary variable. Other ways are to use bit manipulation and math. Temporary Variable
Bit Manipulation
N.B.: i ^= j means i = i XOR j (XOR = eXclusive OR) Don't try to swap the same variable (i.e. swap(&a,&a) ), it will produce incorrect result Math
|
|||||||
| Copyright ©
2004 - Harvest Software |
||||||||