Palindrom-Prüfung mit Queue und Stack in C
# Include
# Include
# Include
# Include
struct Nodop
{
char Wort[15];
};
node
{
struct Nodop pal;
node *next;
};
typedef struct Knoten *Cola;
struct nodoPILA
{
struct Nodop pal2;
struct nodoPILA *siguiente2;
};
typedef struct nodoPILA *Pila;
void crear(COLA *inicio, COLA *final)
{
(*inicio) = NULL;
(*final) = NULL;
}
void crearPILA(PILA *inicio)
{
(*inicio) = NULL;
}
int empty(COLA inicio)
{
if (inicio == NULL)
return 1;
else
return 0;
}
void ingresar(COLA *inicio, COLA *final, char Wort)
{
COLA nuevo;
nuevo = (COLA) malloc(sizeof(node));
nuevo->pal.Wort[0] = Wort;
nuevo->next = NULL;
if ((*final) == NULL)
{
(*final) = nuevo;
(*inicio) = nuevo;
}
else
{
(*final)->next = nuevo;
(*final) = (*final)->next;
}
}
void ingresarPILA(PILA *inicio, char Wort)
{
PILA nuevo;
nuevo = (PILA) malloc(sizeof(struct nodoPILA));
nuevo->pal2.Wort[0] = Wort;
nuevo->siguiente2 = NULL;
if ((*inicio) == NULL)
{
(*inicio) = nuevo;
}
else
{
nuevo->siguiente2 = (*inicio);
(*inicio) = nuevo;
}
}
char mostrar(COLA *inicio, COLA *final)
{
COLA q;
char a;
// printf("\n%f", (*inicio)->pal.Wort);
a = (*inicio)->pal.Wort[0];
if ((*inicio)->next == NULL)
{
free(*inicio);
(*inicio) = NULL;
(*final) = NULL;
}
else
{
q = (*inicio);
(*inicio) = (*inicio)->next;
q->next = NULL;
free(q);
}
return a;
}
char mostrarPILA(PILA *inicio)
{
PILA q;
char b;
b = (*inicio)->pal2.Wort[0];
// printf("\nValor inicio = %f - Wort: %s", (*inicio)->pal2.Wort);
if ((*inicio)->siguiente2 == NULL)
{
free(*inicio);
(*inicio) = NULL;
}
else
{
q = (*inicio);
(*inicio) = (*inicio)->siguiente2;
q->siguiente2 = NULL;
free(q);
}
return b;
}
void main()
{
struct Nodop pal;
COLA inicio;
COLA final;
PILA inicio2;
char a, b;
int i, e, igual;
igual = 0;
i = 0;
e = 0;
clrscr();
crear(&inicio, &final);
crearPILA(&inicio2);
printf("Wort eingeben: ");
gets(pal.Wort);
e = strlen(pal.Wort);
do
{
a = pal.Wort[i];
ingresar(&inicio, &final, a);
ingresarPILA(&inicio2, a);
i++;
} while (i < e);
while (!empty(inicio) && igual == 0)
{
a = mostrar(&inicio, &final);
b = mostrarPILA(&inicio2);
printf("\na = %c - b = %c", a, b);
if (a != b)
igual = 1;
}
if (igual == 1)
printf("\nEs ist kein Palindrom");
else
printf("\nEs ist ein Palindrom");
getch();
}