+ 2
Programme of swaping
can anyone help me in a programme of swap
1 Resposta
+ 2
The swap function, a classic to show the usefulness of passing variables by reference.
void swap(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}
Alternative version, without tmp:
void swap2(int &a, int &b) {
a = a + b;
b = a - b;
a = a - b;
}