// REVISA EL EQUILIBRIO DE LOS PARENTESIS EN UNA EXPRESION
#include <stdio.h>
#include <stdlib.h>
struct Nodo
{
char Dato;
struct Nodo *Sig;
};
struct Nodo *Pila = NULL;
struct Nodo *Crea_Nodo(char LETRA)
{
struct Nodo *Nuevo = (struct Nodo *)malloc(sizeof(struct Nodo ));
Nuevo->Dato = LETRA;
Nuevo->Sig = NULL;
}
void pop()
{
if (!empty()) Pila = Pila->Sig;
else printf("PILA VACIA ... ¡¡¡ ERROR !!!\n");
}
int empty()
{
if ( Pila == NULL ) return 1;
return 0;
}
void push(struct Nodo *Nuevo)
{
if (empty( )) Pila = Nuevo;
else { Nuevo->Sig = Pila; Pila = Nuevo; }
}
int Revise_Parentesis(char *EXPR)
{
int Indice = 0;
while(EXPR[Indice] != '\0')
{
if (EXPR[Indice] == '(') push(Crea_Nodo(EXPR[Indice]));
if (EXPR[Indice] == ')') pop();
Indice++;
}
return empty();
}
void Lee_Expresion(char *Expresion)
{
printf("Introduce una expresiOn matemAtica: ");
gets(Expresion);
}
int main()
{
char *Expresion = (char *)malloc(sizeof(char)*100);
Lee_Expresion(Expresion);
if (Revise_Parentesis(Expresion)) printf("EXPRESION CORRECTA ... \n");
else printf("EXPRESION INCORRECTA ...\n");
return 1;
}