This is the main part of a project
I assume all other header and cpp file are correct
cuz most of them are copy from books n the professor
when I run it, "right after the input"
the program sort of stopped, pop out a error message, then keep running
n crashed after my test part of printing out the "queue"
so I assume there got to be a error for input?!
n maybe when translating from prefix to postfix?
please anyone, help me out by simply point out my error(or maybe it isn't that simple)
I wish to learn from my own error, n help out someone else someday
// LAB2.cpp
#include "Utility.h"
#include "Stack.h"
#include "Queue.h"
#include <iostream>
#include <string>
using namespace std;
void input(Queue prefixQ);
void pre_to_post(Queue prefixQ, Queue postfixQ);
void output(Queue postfixQ);
bool is_operator(char ch);
int main()
{ Queue prefixQ, postfixQ;
char answer;
do
{ input(prefixQ);
pre_to_post(prefixQ, postfixQ);
output(postfixQ);
cout<<endl<<"continue? N for NO: ";
cin>>answer;
} while(!(answer=='n'||answer=='N'));
return 0;
}
void input(Queue prefixQ)
{ string pref;
int i=0;
cin>>pref;
while(pref[i])
{ prefixQ.append(pref[i]);
i++;
}
}
void pre_to_post(Queue prefixQ, Queue postfixQ)
{ Stack_entry se1;
Stack S;
char ch;
while(!prefixQ.empty())
{ prefixQ.retrieve(ch);
prefixQ.serve();
if(is_operator(ch))
{ se1.element=ch;
se1.flag=false;
S.push(se1);
}
else
{ postfixQ.append(ch);
S.top(se1);
while(se1.flag!=false)
{ if(se1.flag==false)
{ se1.flag=true;
S.push(se1);
}
else
{ S.pop();
postfixQ.append(se1.element);
}
S.top(se1);
}
se1.flag=true;
S.push(se1);
}
}
}
void output(Queue postfixQ)
{ char ch;
while(!postfixQ.empty())
{ postfixQ.retrieve(ch);
postfixQ.serve();
cout<<ch;
}
cout<<endl;
}
bool is_operator(char ch)
{ if(ch=='+'||ch=='-'||ch=='*'||ch=='/')
return true;
else
return false;
}