I've been working on this Infix to Postfix for a couple weeks, and I can't seem to figure out why it keeps crashing when i try and do more complicated conversions.

For example:
Input >> 2+3*5
Output >> 235*+

Now thats perfect, it's supposed to look like that but when i try:
Input >> 2+3*(5-6)-4
Output >> 2356(*+ >> "Debug Assertion Failed"
Expected >> 2356-*+4-

I am supposed to be using Dijkstra's algorithm for converting.

ItoP.h
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485`` ``````#include #include #include #include using namespace std; class ItoP { public: string Convert(string); ItoP(); private: stack mystack; string postfix; string infix; string operate; char token; char compare; }; ItoP::ItoP() { } string ItoP::Convert(string inData) { for(int i=0;i<=inData.length();i++) { token = 0; operate.clear(); token = inData[i]; operate += token; if(token >= '1' && token <= '9') { cout << token; //if token is a digit then output token } else { if(token == '(') { mystack.push(operate); //if token is ( then push token to stack } else { if(token == ')') { compare + mystack.top(); while(compare != '(') { mystack.pop(); cout << mystack.top(); compare = 0; compare + mystack.top(); } mystack.pop(); } else { if(mystack.empty()) { mystack.push(operate); } else { compare + mystack.top(); while(!mystack.empty() && token <= compare) { mystack.pop(); cout << mystack.top(); compare = 0; compare + mystack.top(); } mystack.push(operate); } } } } } while(!mystack.empty()) { cout << mystack.top(); mystack.pop(); } cout << endl; return postfix; }``````

ItoP.cpp
 ``12345678`` ``````#include "ItoP.h" int main() { string input; getline(cin,input); ItoP Conl; Conl.Convert(input); return 0; }``````
Topic archived. No new replies allowed.