I am writen this cod but didn't run with me >>>Iam tired please help me to make cod is run.....
import java.util.*;
class infixToPostfix
{
//data fill
private static String expression;
public static String postfix;
private Stack<Character> stack = new Stack<Character>();
//Constructor one argement"-----------"
public infixToPostfix(String infixExpression)
{
expression = infixExpression;
}
//convert the expression to postfix
public String convert()
/**/{
//local Variables
char ch = ' ';
String infix = "";//is input
String postfix = "";//is output
for(int i = 0; i < expression.length(); i++)
{
ch = expression.charAt(i);
if(isOperator(ch))
{
while(!stack.empty() && precedence(stack.peek())>= precedence(ch))
postfix += stack.pop() + " ";
stack.push(ch);
}
else if(ch == '(')
{
stack.push(ch);
}
else if(ch== ')')
{
while(!stack.peek().equals('('))
postfix += stack.pop() + " ";
stack.pop();
}
/* if ones*/ else
{
if(Character.isDigit(ch)&&(i+1)< expression.length()&& Character.isDigit(expression.charAt(i+1)) )//is two digits)
{
postfix += ch;
}
else if(Character.isDigit(ch))//is one digit
{
postfix += ch + " ";
}
else
{
postfix += ch;//
}
}// elseIam using method isDigit()
}//for loop
while(!stack.empty())
{
postfix += stack.pop() + " ";
}
return postfix;
}//convert
public static int precedence(char operator)
{
if(operator == '+' || operator =='-')
return 1;
else if(operator == '*' || operator == '/')
return 2;
else
return 0;
}// precedence
public boolean isOperator(char element)
{
if(element == '*' || element == '-' || element == '/' || element == '+')
return true;
else
return false;
}//isOperator
}
class evaluation{
int finalResult;
Stack <Integer> solu= new Stack<Integer>();
int A,B,result;
public int calculate() {
for(int i=0;i<infixToPostfix.postfix.length();i++){
char c=infixToPostfix.postfix.charAt(i);
switch (c){
case '+':
A=solu.pop();
B=solu.pop();
result=A + B;
solu.push(result);
break;
case '-':
A=solu.pop();
B=solu.pop();
result=A - B;
solu.push(result);
break;
case '*':
A=solu.pop();
B=solu.pop();
result=A * B;
solu.push(result);
break;
case '/':
A=solu.pop();
B=solu.pop();
result=A / B;
solu.push(result);
break;
case '%':
A=solu.pop();
B=solu.pop();
result=A % B;
solu.push(result);
break;
default:
solu.push(Integer.parseInt(Character.toString(c))) ;
break;
}}
finalResult = solu.pop();
return finalResult;
}
}
public class TEST1{
public static void main(String []args) {
infixToPostfix s=new infixToPostfix("5+(9/2*1+1))");
evaluation a=new evaluation();
System.out.println(s.convert());
System.out.println(a.calculate());
}
}