Author Blog: http://blog.9cbs.net/playyueer/ A transformation of the blot-in-antix to the suffix expression To convert the expression from the prefix expression in the form of an equivalent expression C # CODE: // 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
0) / / Stack does not empty {char c = Operators [top -]; // POP Operator if (c == ') {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 = '0' && c <= ') || c =='. ') {OPERAND = C;} IF c == '' && operand! = "" || i == s.length - 1) {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 influence of sequence on division X = OPERANDS [TOP -]; // POP double-purpose operator Operation Switch (C) {CASE ' ': V = X Y; Break; Case '-': V = x - Y; Break; Case '*': v = x * Y; Break; Case '/' : V = x / y; // First operand / second operand attention Operation number sequence on division Break; default: v = 0; Break;} OPERANDS [ TOP] = v; // push middle The result is 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
0) / / Stack does not empty {char c = Operators [top -]; // POP Operator if (c == ') {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