RPN (Reverse Polish Notation) code in C++ ProBLem...?

alatir

New member
i am writing a problem in C++ with class stack and i have a problem in my RPN code (which follows bellow)...
i have two stacks of a class stack the 1st is the profix and the other is the rpn
all my functions are working perfectly
where char *nam3;
temp_size is the size of a stack

while(temp_size>0){
strcpy(nam3, profix.pop().c_str()); //copies the pop into the num3
if(isNumber(nam3)) //isNymber() is a function of mine which checks a string if are all numbers
rpn.push(nam3);
else if( (strcmp(nam3,"+")!=0) && (strcmp(nam3,"-")!=0) && (strcmp(nam3,"*")!=0) && (strcmp(nam3,"/")!=0) ){
cout<<"Error in The Equation";
exit(-1);
}else{
if( (flag_1st) && ( (strcmp(nam3,"+")==0) || (strcmp(nam3,"-")==0) || (strcmp(nam3,"*")==0) || (strcmp(nam3,"/")==0) ) ){ //case i give at first an arithmetic symbol
cout<<"Error in The Equation";
exit(-1);
}else{
num3=rpn_calc(*nam3,GetIntVal(rpn.pop()),GetIntVal(rpn.pop()));
out << num3;
s=out.str();
rpn.push(s);
}
}
flag_1st=false;
temp_size=profix.getSize(); //a function of the class that returns the size

} //while(temp_size>0)

my problem is that when i give 1 2 3 4 + + + it doesnt give the correct answer
but when i give 1 2 3 + + it works...
Please Help Me...
if you have any other code in c++ for RPN i^ll appreciate to help me out...
THANK YOU...
 
Back
Top