#include
#include
#include
#include
#include
#include
int check(char a);
using namespace std;
int main()
{
char s[100];
stackin;
char out[100];
int i=0,z=0,flag=1;
char ch;
system("COLOR F0");
cout << "ENTER A INFIX NOTATION "< cin>>s;
strrev(s);
int x=strlen(s);
while (i ch=s[i];
if((ch == '(')||(ch == ')'))
{
if (ch == '(')
{
in.push(ch);
}
else
{
while((in.top()!='(')&&(!in.empty()))
{
out[z++]=in.top();
in.pop();
}
if(!in.empty())
{
in.pop();
}
}
}
else{
int temp=check(ch);
if(temp==0){
out[z++]=ch;
}
else{
if(in.empty()&&(temp>=1))
{
in.push(ch);
}
else
{
while(temp<=(check(in.top()))&&(!in.empty())&&(in.top()!='('))
{
out[z++]=in.top();
in.pop();
}
in.push(ch);
}
}
}
i++;
}
while (!in.empty()) {
out[z++] = in.top();
in.pop();
}
out[z]=0;
strrev(out);
cout< return 0;
}
int check(char a)
{
switch(a)
{
case '+':
return 1;
case '-':
return 1;
case '*':
return 2;
case '/':
return 2;
case '^':
return 3;
default:
return 0;
}
}
#include
#include
#include
#include
#include
int check(char a);
using namespace std;
int main()
{
char s[100];
stack
char out[100];
int i=0,z=0,flag=1;
char ch;
system("COLOR F0");
cout << "ENTER A INFIX NOTATION "<
strrev(s);
int x=strlen(s);
while (i
if((ch == '(')||(ch == ')'))
{
if (ch == '(')
{
in.push(ch);
}
else
{
while((in.top()!='(')&&(!in.empty()))
{
out[z++]=in.top();
in.pop();
}
if(!in.empty())
{
in.pop();
}
}
}
else{
int temp=check(ch);
if(temp==0){
out[z++]=ch;
}
else{
if(in.empty()&&(temp>=1))
{
in.push(ch);
}
else
{
while(temp<=(check(in.top()))&&(!in.empty())&&(in.top()!='('))
{
out[z++]=in.top();
in.pop();
}
in.push(ch);
}
}
}
i++;
}
while (!in.empty()) {
out[z++] = in.top();
in.pop();
}
out[z]=0;
strrev(out);
cout<
}
int check(char a)
{
switch(a)
{
case '+':
return 1;
case '-':
return 1;
case '*':
return 2;
case '/':
return 2;
case '^':
return 3;
default:
return 0;
}
}
No comments:
Post a Comment