Skip to content

Instantly share code, notes, and snippets.

@erseco
Created January 24, 2015 15:57
Show Gist options
  • Save erseco/7748b25ec1fff9c62877 to your computer and use it in GitHub Desktop.
Save erseco/7748b25ec1fff9c62877 to your computer and use it in GitHub Desktop.
// Diseñar una función orden int orden(list<int> L) que devuelva 1 si L está ordenada de forma ascendente de principio a fin, 2 si lo está de forma descendente y 0 si no está ordenada de ninguna forma.
int orden(list<int> L)
{
int resultado = 0;
list<int>::iterator it = L.begin();
int ant = *it;
++it;
bool asc = true;
bool desc = true;
for (; it!=L.end(); ++it)
{
if (*it>ant)
desc = false;
if (*it<ant)
asc = false;
ant = *it;
}
if (asc)
resultado = 1;
else if (desc)
resultado = 2;
else
resultado = 0;
return resultado;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment