Documentos de Académico
Documentos de Profesional
Documentos de Cultura
3. +
4. )
5. (
* Diagrama de flujo:
pilas
new Stack < String > (); //Pila
new Stack < String > (); //Pila
new Stack < String > (); //Pila
switch (pref(E.peek())){
case 1:
P.push(E.pop());
break;
case 3:
case 4:
while(pref(P.peek()) >= pref(E.peek())) {
S.push(P.pop());
}
P.push(E.pop());
break;
case 2:
while(!P.peek().equals("(")) {
S.push(P.pop());
}
P.pop();
E.pop();
break;
default:
S.push(E.pop());
}
}
//Eliminacion de `impurezas en la expresiones
algebraicas
String infix = expr.replace(" ", "");
String postfix = S.toString().replaceAll("[\\]\\[,]",
"");
//Mostrar resultados:
System.out.println("Expresion Infija: " + infix);
System.out.println("Expresion Postfija: " + postfix);
}catch(Exception ex){
System.out.println("Error en la expresin algebraica");
System.err.println(ex);
}
}
//Depurar expresin algebraica
private static String depurar(String s) {
s = s.replaceAll("\\s+", ""); //Elimina espacios en
blanco
s = "(" + s + ")";
String simbols = "+-*/()";
String str = "";
+
*
/
%
num2);
num2);
num2);
num2);
num2);