Hi..i'm having some trouble coming up with the an algorithm for a problem im working on.
I am trying to check an arithmetic infix expression like:
(((6+2)/2)*(3-1)); //This is my input file(; marks end of line.)
I have to check to see if the statement is ok, or not ok, and if it has either a stack overflow or underflow. For example output would look like:
(((6+2)/2)*(3-1)) is Fine.
(((6+2)/2)*(3-1) is not fine.
((((((((6+2/2)*(3-1)) Stack Overflow!
My algorithm as of now is:
Check to see if files ok
Read 1 char
While (inFile) AND char != ';'
if char == '(' AND stack !isfull()
else if char == ')' AND stack !isempty()
ignore all other characters.
I'm having trouble understanding where and how to output the whole expression and if it is a stack underflow, overflow, or is ok. Also, how do you ignore all other characters (numbers, operators, etc).
Edited 5 Years Ago by xcarbonx: n/a