public static void main(String[] args)
{
int i=0;
int j=0;
char[] str= new char[100]; // array where we can store infix character.
char[] str1= new char[100]; // used in main function for storing prefix character.
char[] stack=new char[100]; // array where we can store operand.
while(true){
top=0;
Scanner mo = new Scanner(System.in);
System.out.print("type the notation : ");
String strr = mo.nextLine();
strr.getChars(0, strr.length(), str, 0);
System.out.println("what you typed : " + strr);
System.out.print("result of the prefix : ");
for(i=0,j=0 ; i<str.length ; i++)
{
if( Character.isDigit(str[i]) ) //if component will digit.
{
str1[j++]=str[i]; //store print value to str1 array for calculating.
System.out.print(str[i]);
if ( i==(str.length-1) ) //if 'i'value would go end of the array.
{
while( top>-1 ) //pop every component from operand stack.
{
pop(stack);
if(temp!=0) //if result of the pop will '(' or ')', we don't store result to str1 array.
{
str1[j++]=temp;
}
}
}
}
else //if component will operand
{
if ( str[i] == '(' || str[i] == ')' ) // if component will '(' or ')'
{
push(stack, str[i]);
if ( str[i] == ')' )
{
while ( stack[top] != '(' )
{
pop(stack);
if(temp!=0) //if result of the pop will '(' or ')', we don't store result to str1 array.
{
str1[j++]=temp;
}
}
pop(stack); // pop '('
if(temp!=0)
{
str1[j++]=temp;
}
if ( i==(str.length-1) ) //if 'i'value would go end of the array.
{
while( top!=0 ) //pop every component from operand stack.
{
pop(stack);
str1[j++]=temp;
}
}
}
}
else if( top > 0 && prior(str[i]) <= prior(stack[top]) ) //if new operand's priority will lower or same with stack's operand's.
{
while(top > 0 && prior(str[i]) <= prior(stack[top])) //pop up to new operand will replace the stack's operand.
{
pop(stack);
str1[j++]=temp;
}
push(stack,str[i]); //push new operand.
}
else //if new operand's priority will higher than stack's
{
push(stack, str[i]);
}
}
}
System.out.print("\n");
// System.out.print("result : ");
//calculate(str1); //calculate function; calculate prefix string
}
}