cs=0;a[j]="";c=0;
String s=in.readLine();
String s1=’(’+s+’)’;
char ch;
l=s1.length();
char brac[]=new char[l];
char ptstr[]=new char[l];
for(i=0;i<l;i++)
{
ch=s1.charAt(i);
if(ch==’(’)
{
brac[c]=ch;
++c;
}
else if(ch==’^’ || ch==’/’ || ch==’*’ || ch==’+’ || ch==’-’ || ch==’%’)
{
if(prec_op(brac[c-1])>0)
{
if((prec_op(ch)>prec_op(brac[c-1]))||(ch==’^’ && brac[c-1]==’^’))
{
brac[c]=ch;
++c;
}
else
`` {
while(prec_op(ch)<=prec_op(brac[–c])) {
ptstr[cs]=brac[c];
++cs; }
brac[++c]=ch;
++c;
} }
else
{
brac[c]=ch;
++c;
} }
else if((ch>=97 && ch<=122)||(ch>=48 && ch<=57)||(ch>=65 && ch<=90))
{
ptstr[cs]=ch;
++cs;
}
else
{ c=c-1;
while(brac[c]!=’(’)
{
ptstr[cs]=brac[c];
++cs;
–c;
} } }
a[j]=String.valueOf(ptstr);
}
public static int prec_op(char ch)
{
switch(ch)
{
case ‘^’ : return 4;
case ‘/’ : return 3;
case ‘*’ : return 3;
case ‘+’ : return 2;
case ‘-’ : return 2;
case ‘(’ : return -1;
default: return 0;
}
}
}
pls help whats wrong with my code… I have submitted it many times bt gives wrong answer plsss help