You are on page 1of 3

#include<iostream.

h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
int ts=-1;
char st[20];
char opr[]={'^','/','*','+','-'};
int k=0,temp1,temp2;
int check(char n)
{
for(int j=0;j<=4;j++)
{
if(opr[j]==n)
{
return j;
}
}
return 0;
}
void push(char n)
{
ts++;
st[ts]=n;
}
char pop()
{
ts--;
return st[ts+1];
}
void main()
{
clrscr();
char a[20],out[20];
cout<<"\n\n\tEnter the input string\t";
gets(a);
for(int i=0;i<strlen(a);i++)
{
if(
((a[i]>=65) && (a[i]<=90)) || ((a[i]>=97) && (a[i]<=122)))
{
out[k]=a[i];
k++;

}
else
{
if(ts==-1)
{
push(a[i]);
}
else
{
temp1=check(st[ts]);
temp2=check(a[i]);
if(temp2<temp1)
{
push(a[i]);
}
else
{
while(temp2>=temp1)
{
out[k]=pop();
k++;
temp1=check(st[ts]);
if(ts==-1)
{
break;
}
}
push(a[i]);
}
}
}
}
while(ts!=-1)
{
out[k]=pop();
k++;
}
cout<<"\n\n\t\t The output string is ";
out[k]='\0';
puts(out);
getch();
}

You might also like