plz simple this code

#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();
}


As a start, you could establish a relationship with the spacebar on your keyboard. Everything rammed together with only minimal spacing is impossible to read. Also, indention is important. And remove the global variables.

closed account (z05DSL3A)
jsmith wrote:
you could establish a relationship with the spacebar on your keyboard
:0)
I think the forum eats the spaces when you don't use [code] [/code] tags. :) Which one should arguably do.
closed account (z05DSL3A)
only at the start of the lines

:0(
else if((stack[top]=='+'||stack[top]=='-')&&(ch=='*'||ch=='/'))

:0|
else if ( (stack[top] == '+' || stack[top] == '-' ) && (ch == '*' || ch == '/' ) )

:0)
else if ( (stack[top] == '+' || stack[top] == '-' ) && (ch == '*' || ch == '/' ) )
Last edited on
Topic archived. No new replies allowed.