make this code simple

#include<iostream.h>
#include<conio.h>
char ch;
int top=-1;
char st[100];
char stack[150];
void exp()
{
top=-1;
}

void input()
{
cout<<"enter expresion without space = ";
cin>>st;
}
void scan(void);
void push(void);
void pop(void);

int main()
{
exp() ;
input();
scan();
getch();
}



void push(void)
{

top=top+1;
stack [top]=ch;
}



void pop()
{
while(top!=-1)
{
if(ch==')')
{
cout<<stack[top]<<" ";
top--;
if(stack[top]=='(')
{
top--;
break;
}
}
else
{
cout<<stack[top]<<" ";
top--;
if(stack[top]=='(')break;
}
}
}
void scan(void)
{
for(int i=0;st[i]!='';i++)
{
ch=st[i];
if(ch=='('||ch=='*'||ch=='/'||ch=='+'||ch=='-'||ch==')')
{
if(ch=='(')
push();
else if(stack[top]=='(')
pop();
else if(ch==')')
pop();
else if((stack[top]=='+'||stack[top]=='-')&&(ch=='*'||ch=='/'))
push();
else if(top==-1)
push();
else
{
pop();
push();
}
}
else
cout<<ch<<" ";
}
pop();
}


Topic archived. No new replies allowed.