The transformation of the prefix expression to the suffix expression to convert the expression from the infix expression in the form of a suffix representation to the equivalent expression representation
C # cote:
// Using system; class class1 {public static void main () {system.console.writeline ("Hello World!"); // Pixel => Suffix Expression String S = "(1.9 (20 41) / (25 * 11) - 3) * 2 "; // is infix; //foxed String s =" "; // suffix char [] Operators = new char [s.Length]; int top = -1; for (INT i = 0; i
{Break;} else {s = s c;}}} S = ""; Break; default: s = s C; Break;}} while (TOP> = 0) {s = s Operators [TOP -]; // Pop Operator} system.console.writeline (s); // suffix
// Suffix expression calculates Double [] Operands = new double [s.Length]; Double X, Y, V; TOP = - 1; String Operand = ""; for (int i = 0; i
IF ((c == '|| i == s.length - 1) && operand! = "" "// update {Operands [ TOP] = system.convert.todouble (Operand); // push Operands Operand = "";
IF (c == ' ' || c == '-' || c == '*' || c == '/') {IF ((Operand! = ")) {OPERANDS [ TOP ] = System.convert.todouble (operand); // push operands operand = "";} y = OPERANDS [TOP ---]; // POP binocular operator's second operand (then first out) pay attention to operand The sequence of sequential impact X = OPERANDS [TOP ---]; // POP double-purpose operator's first operand Switch (C) {case ' ': v = x y; Break; Case '-': V = x - y; breaf; case '*': v = x * y; break; case '/': v = x / y; // First operand / second operand pay attention to operational number sequence on division Break; default: v = 0; Break;} OPERANDS [ TOP] = V; // push intermediate results again in the stack}} v = Operands [TOP ---]; // POP final result System.Console.writeLine v); system.console.readline ();}}
Java Code:
Class class1 {public static void main (String [] args) {system.out.println ("Hello World!"); // Pixel => Suffix Expression String S = "(1.9 (20 41) / ( 25 * 11) - 3) * 2 "; // Fox string s =" "; // suffix char [] Operators = new char [s.Length ()]; int top = -1; for (int i = 0; I
) {Break;} else {s = S C;}} S = ""; Break; default: // operand S = S C; Break;}} while (TOP> = 0) {s = s Operators [TOP ---]; // Pop Operator} system.out.println (s); // suffix
// Suffix expression calculates Double [] Operands = new double [S.Length ()]; Double X, Y, V; TOP = - 1; String Operand = "; for (int i = 0; i
IF ((c == '|| i == s.Length () - 1) && operand! = "") // update {operands [ TOP] = java.lang.double.Parsedouble (OPERAND); // push operands Operand = "";
IF (c == ' ' || c == '-' || c == '*' || c == '/') {IF ((Operand! = ")) {OPERANDS [ TOP ] = java.lang.double.parsedouble (Operand); // push operands Operand = ";} y = OPERANDS [TOP -]; // POP double-purpose operator's second operand (then first out) Operating sequence affects the impact of the division x = OPERANDS [TOP ---]; // POP double-purpose operator's first operand Switch (c) {case ' ': v = x y; Break; Case '-' : V = x - y; Break; case '*': v = x * y; breaf; case '/': v = x / y; // First operand / second operand Note Operation number sequence Influence Break; default: v = 0; Break;} OPERANDS [ TOP] = V; // Push intermediate result is again incoming stack}} v = Operands [TOP--]; // POP final result system.out. Println (V);}}