I have the following problem on my C++ Program and I am not sure why it is not working. I am creating a infix to postfix program through an inherited class which I am not sure it is working. I have been working on this for days and any help would help. Thanks
#include <iostream>
#include <stack>
using namespace std;
int in_stack_Priority(char a){
if(a == '*' || a == '/')
return 2;
if(a== '+' || a == '-')
return 1;
if(a == '(')
return 0;
}
int in_coming_Priority(char a){
if(a == '*' || a == '/')
return 2;
if(a== '+' || a == '-')
return 1;
if(a == '(')
return 4;
}
template<class datatype>
class cstack :public clinkedlist<datatype>{
private:
//Linked List class inherited to make a stack class
public:
cstack();
void push(datatype data);
datatype pop(void);
datatype top(void);
bool stackempty(void);
};
template<class datatype>
cstack<datatype>::cstack(){
clinkedlist<datatype>;
};
template<class datatype>
void cstack<datatype>::push(datatype data){ //push data all defined down here
insertbegin(data);
};
int main()
{
cstack<char> x;
clinkedlist<char> infix, postfix; <inherited class to create program, using Linked List to create the program>
char c;
bool endflag = true;
c = cin.get(); //getting user input
while(c != ';')
{
infix.insertend(c);
}
if(infix.listempty())
{
endflag=false;
}
infix.insertend(';');
}else{
if(x.stackempty())
x.push(c);
else{
bool flag_x = true; //checking the operator priority. Is it of higher priority or not
while(flag_x== true && !x.stackempty()){
if (in_stack_Priority(x.top())>= in_coming_Priority(c)){
c = x.pop();
postfix.insertend(c);
}else{
flag_x= false;
}
x.push(c);
}
}
}
}
infix.moveCurrentnext();
if(c == ';')If it is ; then the program is set to false, the flag is set to false again
{
endflag = false;
while(!x.stackempty()){ <clears everything in the stack and inserts it
postfix.insertend(c);
}
}
cout<<"The postfix is " << &postfix<<endl;
That's too much code to wade through without code tags, proper indentation or comments. Please edit your post so that it is readable.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/