/ Published in: C

swap: swap two numbers without using the third object( or variable)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// solution one // template <class T> void swap(T *a, T *b){ *a = *a + *b; *b = *a - *b; *a = *a - *b; } // solution two // template <class T> void swap(T &a, T &b){ a = a * b; b = a / b; a = a / b; }
Comments
