Suppose you have two variables x and y and you want to swap their values. The usual way to do this is using another temporary variable:
temp = x;
x = y;
y = temp;
However, the interchange of two variables can be done without the temp variable:
x = x + y;
y = x - y;
x = x - y;
What is your favourite algorithm for swapping variables?
x ^= y ^= x ^= y;
though this exact wording is not recommended.
it is do not work in java. this code in C++.
t = x;
x = y;
y = t;
else
p = x;
x = y;
y = t;
Oh, sorry... my bad English... it`s in past time...
I say, that swap can swapping structs and other variable...