Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 7, 2019 16:10
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 parzibyte/d56815fd9a608f0fdbf5f2e965b15442 to your computer and use it in GitHub Desktop.
Save parzibyte/d56815fd9a608f0fdbf5f2e965b15442 to your computer and use it in GitHub Desktop.
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