I am really very sorry. I dint get what you are trying to say =((!!
When we encounter an opening symbol why we push the corresponding closing symbol??
Printable View
How about this??Code:while ( input != 13 )
{
if input is '(' or '{' or '[' or ')' or '}' or ']'
{
if input is '(' or '{' or '['
push it into the stack.
else if input is ')' or '}' or ']'
{
if stack is empty
report error.
pop cell from stack
if cell "matches input"
we are ok.
else if cell dont "matches input" or stack is empty
report error.
}
}
}
if the stack is not empty
report error.
Very good.
A couple of possible issues to be aware of, though:
1) The stopping condition should be on the null-terminator (0, the end of the string), not a newline (13).
2) The condition 'if cell "matches input"' would be incorrect, considering that if the input, for instance, is a closing bracket, then the cell should be an opening bracket. This is actually why it was suggested to push the 'closing' symbol, as it would make the checking logic a little simpler.
3) It's probably necessary to implement an 'is_empty' member function, or similar.
Everything else looks pretty close to being correct. Try to implement it in code now, and see what you come up with.