Created
August 7, 2019 16:10
-
-
Save parzibyte/d56815fd9a608f0fdbf5f2e965b15442 to your computer and use it in GitHub Desktop.
This file contains 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
int esPalindromoConWhile(char * cadena) { | |
int longitud = strlen(cadena); | |
// Cadenas de 1 o menos son, por definición, recursivas | |
if (longitud <= 1) return 1; | |
// Comenzamos en el inicio y fin de la cadena | |
int inicio = 0, fin = longitud - 1; | |
// Mientras el primer y último carácter sean iguales | |
while (cadena[inicio] == cadena[fin]){ | |
// Aquí sólo resta un carácter por comparar, eso indica que SÍ es palíndroma | |
if (inicio >= fin) return 1; | |
// Vamos acortando la cadena | |
inicio++; | |
fin--; | |
} | |
// Si termina el ciclo y no se rompió, entonces no es palíndroma | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment