Created
January 24, 2015 15:57
-
-
Save erseco/7748b25ec1fff9c62877 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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