Infix To Postfix C++ Code
Infix To Postfix C++ Code
#include<string>
#define MAX 20
char stk[20];
int top=-1;
string infix;
// Push function here, ebinserts value in stack and increments stack top by 1
class stackop
public:
if(top==MAX-1)
cout<<"stackfull!!!!";
else
top++;
stk[top]=oper;
char pop()
char ch;
if(top==-1)
{
cout<<"stackempty!!!!";
else
ch=stk[top];
stk[top]='\0';
top--;
return(ch);
return 0;
};
class pref
public:
return(1);
return(2);
if(alpha == '$')
{
return(3);
return 0;
};
public:
string convert()
int i=0;
while(infix[i]!='\0')
postfix.insert(postfix.end(),infix[i]);
i++;
push(infix[i]);
i++;
if(infix[i]==')')
{
while(stk[top]!='(')
postfix.insert(postfix.end(),pop());
pop();
i++;
if(infix[i]==']')
while(stk[top]!='[')
postfix.insert(postfix.end(),pop());
pop();
i++;
if(infix[i]=='}')
while(stk[top]!='{')
postfix.insert(postfix.end(),pop());
pop();
i++;
else
if(top==-1)
{
push(infix[i]);
i++;
postfix.insert(postfix.end(),pop());
while(priority(stk[top]) == priority(infix[i])){
postfix.insert(postfix.end(),pop());
if(top < 0) {
break;
push(infix[i]);
i++;
push(infix[i]);
i++;
while(top!=-1)
postfix.insert(postfix.end(),pop());
cout<<"The converted postfix string is : "<<postfix; //it will print postfix conversion
return postfix;
};
int main()
int cont;
string postfix;
intopost e;
cin>>infix;
postfix = e.convert();
return 0;