示例#1
0
        private String postOrder(NodoArbol inicio)
        {
            string ss = null;

            if (inicio != null)
            {
                ss = postOrder(inicio.getIzq()) + postOrder(inicio.getDer()) + inicio.getOperando();
            }
            return(ss);
        }
示例#2
0
        private int ContarNodo(NodoArbol inicio)
        {
            int contador = 0;

            if (inicio != null)
            {
                contador = 1 + ContarNodo(inicio.getIzq()) + ContarNodo(inicio.getDer());
            }
            return(contador);
        }
示例#3
0
        private int buscar1(NodoArbol inicio, string nodo, int count)
        {
            int result = 0;

            if (inicio != null)
            {
                if (nodo.Equals(inicio.getOperando()))
                {
                    return(count);
                }
                result = buscar1(inicio.getIzq(), nodo, count++);
                if (result == 0)
                {
                    result = buscar1(inicio.getDer(), nodo, count++);
                }
            }
            return(result);
        }
示例#4
0
        private NodoArbol buscar(NodoArbol inicio, string nodo)
        {
            NodoArbol result = null;

            if (inicio != null)
            {
                if (nodo.Equals(inicio.getOperando()))
                {
                    return(inicio);
                }
                result = buscar(inicio.getIzq(), nodo);
                if (result == null)
                {
                    result = buscar(inicio.getDer(), nodo);
                }
            }
            return(result);
        }
示例#5
0
        private void pintarArbol2(Graphics Graph, int x, int y, NodoArbol nodo, String direccion, int cont, int ancho)
        {
            Pen pen = new Pen(Color.Black);

            if (nodo != null)
            {
                if (direccion.Equals("Raiz"))
                {
                    Graph.DrawEllipse(pen, x - 7, y, 30, 30);
                    Graph.FillEllipse(Brushes.Yellow, x - 7, y, 30, 30);
                    Graph.DrawString(nodo.getOperando(), new Font("Arial", 12), Brushes.Black, x, y + 6);

                    x = x - 7;
                }
                else if (direccion.Equals("Izq"))
                {
                    int xActual = x;
                    Graph.DrawLine(pen, x, y + 15, x - ancho / (int)Math.Pow(2, cont) + 15, y + 45);
                    Graph.DrawEllipse(pen, x - ancho / (int)Math.Pow(2, cont), y + 30, 30, 30);
                    Graph.FillEllipse(Brushes.Yellow, x - ancho / (int)Math.Pow(2, cont), y + 30, 30, 30);
                    Graph.DrawString(nodo.getOperando(), new Font("Arial", 12), Brushes.Black, x - ancho / (int)Math.Pow(2, cont) + 7, y + 36);

                    x = x - ancho / (int)Math.Pow(2, cont);
                    y = y + 45;
                }
                else if (direccion.Equals("Der"))
                {
                    Graph.DrawLine(pen, x + 30, y + 15, x + ancho / (int)Math.Pow(2, cont) + 15, y + 45);
                    Graph.DrawEllipse(pen, x + ancho / (int)Math.Pow(2, cont), y + 30, 30, 30);
                    Graph.FillEllipse(Brushes.Yellow, x + ancho / (int)Math.Pow(2, cont), y + 30, 30, 30);
                    Graph.DrawString(nodo.getOperando(), new Font("Arial", 12), Brushes.Black, x + ancho / (int)Math.Pow(2, cont) + 7, y + 36);
                    x = x + ancho / (int)Math.Pow(2, cont);
                    y = y + 45;
                }
                pintarArbol(Graph, x, y, nodo.getIzq(), "Izq", cont + 1, ancho);
                pintarArbol(Graph, x, y, nodo.getDer(), "Der", cont + 1, ancho);
            }
        }
示例#6
0
        private String operar(NodoArbol inicio)
        {
            NodoArbol result = null;

            if (inicio.getIzq() != null)
            {
                operar(inicio.getIzq());
            }
            if (inicio.getDer() != null)
            {
                operar(inicio.getDer());
            }
            if (inicio.getIzq() != null && inicio.getDer() != null)
            {
                if (inicio.getIzq().esHoja() && inicio.getDer().esHoja())
                {
                    try
                    {
                        double operacion = realizarOperacion(inicio.getIzq().getOperando(), inicio.getOperando(), inicio.getDer().getOperando());
                        inicio.setOperando(operacion.ToString());
                        inicio.setIzq(null);
                        inicio.setDer(null);
                        result = inicio;
                    }
                    catch (Exception eee)
                    {
                        throw new Exception("Se esta intentando dividir entre cero");
                    }
                }
            }
            else if (inicio.getIzq() == null && inicio.getDer() != null)
            {
                try
                {
                    if (inicio.getDer().esHoja())
                    {
                        double operacion = realizarOperacion("0", inicio.getOperando(), inicio.getDer().getOperando());
                        inicio.setOperando(operacion.ToString());
                        inicio.setIzq(null);
                        inicio.setDer(null);
                        result = inicio;
                    }
                }
                catch (Exception eee)
                {
                    throw new Exception("Se esta intentando dividir entre cero");
                }
            }
            else if (inicio.getDer() == null && inicio.getIzq() != null)
            {
                try
                {
                    if (inicio.getIzq().esHoja())
                    {
                        double operacion = realizarOperacion(inicio.getIzq().getOperando(), inicio.getOperando(), "0");
                        inicio.setOperando(operacion.ToString());
                        inicio.setIzq(null);
                        inicio.setDer(null);
                        result = inicio;
                    }
                }
                catch (Exception eee)
                {
                    throw new Exception("Se esta intentando dividir entre cero");
                }
            }

            return(raiz.getOperando());
        }