Skip to content

Instantly share code, notes, and snippets.

@congdanhqx-zz
Last active July 7, 2016 09:44
Show Gist options
  • Save congdanhqx-zz/ce8f29f0708ca4b84bd6b5d3c43370fb to your computer and use it in GitHub Desktop.
Save congdanhqx-zz/ce8f29f0708ca4b84bd6b5d3c43370fb to your computer and use it in GitHub Desktop.
#include <memory>
int a;
int b;
void swap1(void)
{
int t = a;
a = b;
b = t;
}
// Don't try to be smart guy
void swap2(void)
{
a ^= b;
b ^= a;
a ^= b;
}
// Don't try to be smart guy
void swap3(void)
{
b += a;
a = b - a;
b -= a;
}
// Obviously, this can be done only in C++
void swap4(void)
{
std::swap(a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment