Infijo Post
Infijo Post
Infijo Post
import java.util.Scanner;
import java.util.Stack;
//Entrada de datos
System.out.println("*Escribe una expresión algebraica: ");
Scanner leer = new Scanner(System.in);
try {
//Algoritmo Infijo a Postfijo
while (!E.isEmpty()) {
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());
}
}
//Mostrar resultados:
System.out.println("Expresion Infija: " + infix);
System.out.println("Expresion Postfija: " + postfix);
}catch(Exception ex){
System.out.println("Error en la expresión algebraica");
System.err.println(ex);
}
}