We have an assignment to convert infix to postfix. And I have made this initial code. When this program is executed, I'd type any word that is not an operator or '(' or ')'. For example my input is "asd"
my output should be "asd" also. But in this code the ouput is only 'd'. Kindly how to fix this problem? tnx!
#include<iostream>
#include<cstdlib>
using namespace std;
const int size=50;
char infix[size], postfix[size], stack[size];
bool isOperator(char);
void push(char);
char pop();
void convertToPostfix(char infix);
int precedence(char operator1, char operator2);
char stackTop();
bool isEmpty();
void printStack();
int main()
{
int j=0;
char a, b, c;
cout<<"Enter infix notation: ";
gets(infix);
for(int i=0; infix[i] != '\0' ; i++)
{
int j=0;
char a, b, c;
a=infix[i];
if((!isOperator(a))&& (a != '(') &&(a != ')' ))
{
postfix[j++]= infix[i];
}
}
cout<<"Equivalent postfix notation: "<<postfix<<endl;
system("PAUSE");
return 0;
}
bool isOperator(char symbol)
{
if((symbol=='+') ||(symbol=='-') || (symbol=='*') || (symbol=='/') ||(symbol=='%') ||(symbol=='^'))
return true;
else
return false;
}