Skip to content

Instantly share code, notes, and snippets.

@Reflej0
Created April 14, 2018 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reflej0/765330a49c6372c7899dfb1eab552ad8 to your computer and use it in GitHub Desktop.
Save Reflej0/765330a49c6372c7899dfb1eab552ad8 to your computer and use it in GitHub Desktop.
Intercambio de Variables en C (métodos no tradicionales)
///Intercambio utilizando algebra de bool.
void intercambio_algebra_bool(int* a, int* b)
{
*a ^= *b;
*b ^= *a;
*a ^= *b;
}
///Intercambio utilizando operadores += -=
void intercambio_aritmetica_mejorada(int* a, int* b)
{
*a += (*b);
*b = (*a)-(*b);
*a -= (*b);
}
///Intercambio utilizando aritmetica.
void intercambio_arimetica(int* a, int* b)
{
*a = (*a)+(*b);
*b = (*a)-(*b);
*a = (*a)-(*b);
}
///Intercambio tradicional con una variable auxiliar.
void intercambio_tradicional(int* a, int* b)
{
int aux = *a;
*a = *b;
*b = aux;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment