EXPRESSION TREE from an operation closed by keyboard [closed]

2

Could someone please help me with the java code of how to build an expression tree and calculate its result, from an operation entered by keyboard, I know that batteries should be used, but I do not know where to use them

 public class ArbolExp {

    Nodo raiz;
    Nodo actual;

    public ArbolExp() {
        raiz = null;
        actual = null;
    }

    public boolean Operador(char x) {
        char[] lista = {'+', '-', '/', '*'};
        int cont = 0;
        for (int i = 0; i < lista.length; i++) {
            if (x == lista[i]) {
                cont += 1;
            }
        }
        if (cont == 1) {
            return true;
        } else {
            return false;
        }
    }

    public void Insertar1(char x) {
        Stack pila = new Stack();
        Nodo nuevo = null;
        Nodo aux = raiz;
        if (x == '(') {
            if (raiz == null) {
                raiz = nuevo;
                pila.push(nuevo);
            } else {
                if (aux.izq == null) {
                    aux.izq = nuevo;
                    pila.push(nuevo);
                    aux = aux.izq;
                } else {
                    aux.der = nuevo;
                    pila.push(nuevo);
                    aux = aux.der;
                }
            }
        } else {
            if (Operador(x) == false) {
                if (aux.izq == null) {
                    aux.izq = nuevo;
                } else {
                    aux.der = nuevo;
                    pila.pop();
                }
            } else {
                aux = nuevo;
            }

        }
    }
}
    
asked by Carlos Juca 15.12.2018 в 01:34
source

0 answers