- Swap the values of two numbers without defining a variable
int temp = a;
a = b;
b = temp;
can be replaced with:
a = a ^ b;
b = a ^ b;
a = a ^ b;
For details, see Tips – Use XOR to replace the original constant exchange
- Use >> to replace the original /2 to take the midpoint
int mid = (left + right) / 2;
int mid = left + ((right - left) >> 1); /