// Fabio Andres Palmieri Villa
// fabioandresp.blogspot.com
// Puede ser usado solamente con fines academicos
// si es respetado este encabezado
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
#include "function.h" #include "nodeInt.h"
#include "nodeOp.h"
int main(){
clrscr();
char * expr = "1111+++";
nodeInt* number = 0;
nodeChar* operators = 0;
int n = strlen(expr);
int i = 0;
int correct = TRUE;
while( (i<n) && (correct==TRUE) ) {
cout<<endl<<"Current Symbol : "<<expr[i]<<endl;
if ( isNumeric(expr[i]) ){
// stack each number
number = stack(number,Convert(expr[i])) ;
}else{
if ( isOperator(expr[i])) {
// stack each operator
operators = stack(operators,expr[i]);
}else{
cout<<"Error!";
}
}
cout<<"Stack Numbers: ";
View(number);
cout<<"Stack Operators: ";
View(operators);
cout<<endl<<"Size
#op="<<size(operators)<<"\t#nums="<<size(number)<<endl;
if ( (size(operators)>=size(number)) ){
correct = FALSE;
};
i = i + 1;
}
if (correct==TRUE && ( size(number)-size(operators)==1 ) ){
if (size(number)==1){
cout<<"Resultado=="<<number->n;
getch();
exit(0);
}
cout<<"Expression is formed correctly"<<endl<<endl<<endl;
int a = 0;
int b = 0;
char c = 0;
int resp = 0;
int TODO = TRUE;
while( TODO ){
cout<<"Stack Numbers: ";
View(number);
cout<<"Stack Operators: ";
View(operators);
if (size(number)==2 && size(operators)==1){
TODO = FALSE;
//has been found the terminal expression numb,numb,op
}
a = gethead(number);
b = gethead(number);
c = gethead(operators);
resp = calc(a,b,c);
cout<<a<<c<<b<<endl;
addlast(number, resp );
getch();
};
cout<<endl<<"Resultado = "<<resp;
}else{
cout<<"Incorrect Expression";
}
getch();
return 0;
}