I am working on the last part of my conversion, evaluate the operator function alogorithm of my code called next op. I have it written out on paper but I am having problems converting it to code.
I have this class included in my program
class stack_type _
public:
stack_type( void );
push( char Item );
char pop(void );
bool IsEmpty (void);
private:
char Stack[MAX_ITEMS];
int ItemCount;
This is the alogorithm I need help coding. It is in my main function:
Set done to false
Repeat
If operator stack is empty or next operator is ‘)’,
Push next operator onto stack and set done to true
Else if precedence (next operator) > precedence(top operator)
Push next operator onto the stack
(ensures higer precedence operators evaluated first)
Set done to true
Else
Pop the operator stack
If operator popped is ‘(‘,
Set done to true
Else
Pop right and left from operand stack
Evaluate left operator right
Push result onto operand stack
Until Done