What doesn't make sense to me is that i was given the algorithm to use for this program, and it looks to me that I matched it but maybe i'm off more than i think. Here's the logic:
Infix to Postfix Write a C++ program that will accept infix expressions (like 5*(4+8)) and convert them to postfix. You are to use Dijkstra's algorithm for converting.
Algorithm:
Read in 1 line into a string
Print the string
while there are characters left to process in the string do
-----
| get a token (skip over blanks)
| if the token is a digit then output(token)
| else
| -----
| | if the token is '(' then push(token)
| | else
| | -----
| | | if the token is ')' then
| | | -----
| | | | while the top item is not '('
| | | | pop(temp) and output(temp);
| | | | pop(temp)
| | | -----
| | | else
| | | -----
| | | | if the stack is empty then push(token)
| | | | else
| | | | -----
| | | | | while the stack is not empty
| | | | | and the priority (token) <= priority (top item on the stack)
| | | | | pop and output(temp)
| | | | | push(token)
| | | | -----
| | | -----
| | ----
| -----
-----
while the stack is not empty do pop and output(temp)
The pop's match up but as you said are definitely popping empty stack.
i changed to order of the pops and that seemed to help, the program runs longer but will still hit that same error almost at the end of code. I though the point of the declaration: !mystack.empty() was supposed to keep it from doing this?