i am trying to convert a string from infix to postfix but not getting the desired output
my code is as follows:
#include<iostre am>
#include<stdio. h>
#include<conio. h>
#include<ctype. h>
using namespace std;
int expr();
int term();
int match(int t);
int lookahead=0;
int expr()
{
term();
while(true)
{
if(lookahead = '+')
{
match('+');
term();
putchar('+');
}
else if(lookahead = '-')
{
match('-');
term();
putchar('-');
}
else
break;
}
}
int term()
{
if( isdigit (lookahead))
{
cout<<lookahead ;
match(lookahead );
}
else
cout<<"syntax error";
}
int match(int t)
{
if(lookahead==t )
lookahead=getch ar();
else
cout<<"syntax error";
}
int main()
{
cout<<"Enter an infix epression"<<end l;
lookahead=getch ar();
cout<<"postfix expression is :";
expr();
getch();
return 0;
}
my code is as follows:
#include<iostre am>
#include<stdio. h>
#include<conio. h>
#include<ctype. h>
using namespace std;
int expr();
int term();
int match(int t);
int lookahead=0;
int expr()
{
term();
while(true)
{
if(lookahead = '+')
{
match('+');
term();
putchar('+');
}
else if(lookahead = '-')
{
match('-');
term();
putchar('-');
}
else
break;
}
}
int term()
{
if( isdigit (lookahead))
{
cout<<lookahead ;
match(lookahead );
}
else
cout<<"syntax error";
}
int match(int t)
{
if(lookahead==t )
lookahead=getch ar();
else
cout<<"syntax error";
}
int main()
{
cout<<"Enter an infix epression"<<end l;
lookahead=getch ar();
cout<<"postfix expression is :";
expr();
getch();
return 0;
}
Comment