Created
September 7, 2020 16:47
-
-
Save jmlon/a7c94dc253dd1dd6d5fb0be748c4b019 to your computer and use it in GitHub Desktop.
Ejercicio para convertir expresiones aritmeticas entre formatos: prefijo, postfijo, infijo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.NoSuchElementException; | |
import edu.princeton.cs.algs4.Stack; | |
import edu.princeton.cs.algs4.StdIn; | |
import edu.princeton.cs.algs4.StdOut; | |
public class InfijaPostfijaPrefija { | |
static class Node { | |
Double value; | |
String operador; | |
Node left,right; | |
Node(Double value) { | |
this.value = value; | |
} | |
Node(String operador, Node left, Node right) { | |
this.operador = operador; | |
this.left = left; | |
this.right = right; | |
} | |
public String toString() { | |
if (value!=null) return value.toString(); | |
return operador; | |
} | |
} | |
public static void infix(Node node) { | |
// TODO: Imprimir expresion en notacion infija | |
} | |
public static void postfijo(Node node) { | |
// TODO: Imprimir expresion en notacion postfija | |
} | |
public static void prefijo(Node node) { | |
// TODO: Imprimir expresion en notacion prefija | |
} | |
public static void main(final String[] args) { | |
final Stack<Node> pila = new Stack<>(); | |
while (StdIn.hasNextLine()) { | |
try { | |
final String token = StdIn.readString(); | |
Node a, b; | |
switch(token) { | |
case "+": | |
case "-": | |
case "*": | |
case "/": | |
// TODO: Implementar manejo de operadores | |
break; | |
default: | |
// TODO: Implementar manejo de valores | |
} | |
} | |
catch(NoSuchElementException e) {} | |
} | |
Node root = pila.pop(); | |
infix(root); | |
// prefijo(root); | |
// postfijo(root); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment