postfix to infix conversion in c++ prograqmme
#include<stack>
#include <iostream>
using namespace std;
bool checking_operand(char c)
{
return (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z');
}
string ConvertPostToInfix(string text)
{
stack<string> s1;
for (int i=0; text[i]!='\0'; i++)
{
if (checking_operand(text[i]))
{
string op(1, text[i]);
s1.push(op);
}
else
{
string op1 = s1.top();
s1.pop();
string op2 = s1.top();
s1.pop();
s1.push("(" + op2 + text[i] +
op1 + ")");
}
}
return s1.top();
}
int main()
{
string st= "fb*c+";
cout << ConvertPostToInfix(st);
return 0;
}
Comments
Leave a comment