Example #1
0
 // ----------------------------------------------------------------------------
 public void Agregar(object pElem)
 {
     if (Raiz == null)
     {
         Raiz = pElem;
     }
     else
     if (pElem.ToString().CompareTo(Raiz.ToString()) < 0)
     {
         if (SubArbolIzq == null)
         {
             SubArbolIzq = new CArbolBB(pElem);
         }
         else
         {
             SubArbolIzq.Agregar(pElem);
         }
     }
     else      // pElem.ToString().CompareTo(arbol.Raiz.ToString()) > 0
     {
         if (SubArbolDer == null)
         {
             SubArbolDer = new CArbolBB(pElem);
         }
         else
         {
             SubArbolDer.Agregar(pElem);
         }
     }
 }
Example #2
0
        public async Task <IActionResult> PutRaiz(int id, Raiz raiz)
        {
            if (id != raiz.raizlId)
            {
                return(BadRequest());
            }

            _context.Entry(raiz).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RaizExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public void ConstructFPTree(Dictionary <List <string>, int> Transactions, double minSup)
        {
            //Guarda, para cada producto (El string es el identificador del producto) el numero de veces que aparece en las transacciones.
            Dictionary <string, int> numberOfOcurrances = new Dictionary <string, int>();

            foreach (List <string> list in Transactions.Keys)
            {
                int times = Transactions[list];
                foreach (string ident in list)
                {
                    if (numberOfOcurrances.ContainsKey(ident))
                    {
                        numberOfOcurrances[ident] += times;
                    }
                    else
                    {
                        numberOfOcurrances.Add(ident, times);
                        items.Add(ident);
                    }
                }
            }

            items = items.OrderByDescending(i => numberOfOcurrances[i]).ToList();

            foreach (List <string> trans in Transactions.Keys)
            {
                List <string> ordered = trans.OrderByDescending(e => numberOfOcurrances[e]).ToList();

                Raiz.InsertarTransaccion(ordered, ultimoListaEnlazada, primeroListaEnlazada, (int)Math.Ceiling(minSup * Transactions.Count), numberOfOcurrances, Transactions[trans]);
            }
        }
        public String raiz(double numero)
        {
            // Creo objeto Nlog y escribo la operación en el registro la operación.
            var logger = NLog.LogManager.GetCurrentClassLogger();

            string json   = "";
            double num    = 0;
            Raiz   desRaz = new Raiz();
            Random random = new Random();

            id = random.Next(0, 100);

            // Recibe el objeto en formato JSON y lo almaceno en un objeto de tipo Raiz.
            using (var streamReader = new StreamReader(HttpContext.Request.Body))
            {
                var result = streamReader.ReadToEnd();
                try
                {
                    desRaz = JsonConvert.DeserializeObject <Raiz>(result);


                    num = Convert.ToDouble(desRaz.num);

                    desRaz.resultado = WebApplication1.Models.Calculadora.raiz(num);



                    // Creo un objeto operacion y almaceno sus datos
                    op.Tipo = "Raiz";

                    op.Calculo += "√" + desRaz.num + " = " + desRaz.resultado;

                    DateTime fecha = DateTime.Now;

                    op.Fecha = Convert.ToString(fecha);

                    // Convierto el objeto a JSON y lo añado la operación al listado general

                    JournalList.Listado.Add(id, JsonConvert.SerializeObject(op));

                    // Añado nuevas propiedades al objeto, lo serializo y lo envío
                    Response.Clear();
                    Response.ContentType = "application/json; charset=utf-8";
                    var json2 = JsonConvert.SerializeObject(desRaz);
                    Response.WriteAsync(json2);


                    logger.Info("Operación de raíz cuadrada");
                }
                catch
                {
                    Error500();
                }
            }



            return("");
        }
Example #5
0
        static void Main()
        {
            Raiz nuevaRaiz = new Raiz();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MenuInicial());
        }
Example #6
0
        public void InverterArvoreBinaria()
        {
            Console.WriteLine("\n\nInvertendo Arvore...");
            No filhoEsq = Raiz.GetFilhoEsq();
            No filhoDir = Raiz.GetFilhoDir();

            Raiz.InserirFilhoEsq(filhoDir);
            Raiz.InserirFilhoDir(filhoEsq);
        }
Example #7
0
        public void RaizQuadradaBasicaTeste02()
        {
            Raiz   r             = new Raiz();
            double esperado      = 3.0;
            double entrada       = esperado * esperado;
            double resultadoReal = r.RaizQuadrada(entrada);

            Assert.AreEqual(esperado, resultadoReal, esperado / 100);
        }
Example #8
0
        public string ToFixedSizeString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Grado.ToString().PadLeft(2, '0'));
            sb.Append('|');
            sb.Append(Raiz.ToString().PadLeft(2, '0'));
            sb.Append('|');
            sb.Append(Disponible.ToString().PadLeft(2, '0'));
            return(sb.ToString());
        }
Example #9
0
        private static void Interpreter3()
        {
            var esquerda  = new Multiplicacao(new Numero(2), new Numero(10));
            var direita   = new Divisao(new Numero(20), new Numero(10));
            var resultado = new Multiplicacao(esquerda, direita);

            Console.WriteLine(resultado.Avalia());

            var resultadoRaiz = new Raiz(resultado);

            Console.WriteLine(resultadoRaiz.Avalia());
        }
Example #10
0
 public void Open(String Key, String Path)
 {
     try
     {
         this.Path = Path;
         this.Raiz = Raiz.Read(Path, Key);
         this.Key  = Key;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Senha inválida");
     }
 }
Example #11
0
        public static void raiz()
        {
            string linea2 = "";

            Console.WriteLine("Has Escogido la raíz cuadrada");
            string urlAddress = "https://calculadora20190401125057.azurewebsites.net/Calculadora/Raiz";

            Console.WriteLine("Introduce el número para calcular su raiz");
            Raiz raiz = new Raiz();

            linea2   = Console.ReadLine();
            raiz.num = linea2;

            sendJson(urlAddress, raiz);
        }
Example #12
0
        public void RaizQuadraNumeroMenorQueZero()
        {
            Raiz   r       = new Raiz();
            double entrada = -9.0;

            try
            {
                r.RaizQuadrada(entrada);
            }
            catch (ArgumentOutOfRangeException e)
            {
                StringAssert.Contains(e.Message, Raiz.msgErroRaizValorNegativo);
                return;
            }
            Assert.Fail("O método não lançou a exceção esperada.");
        }
Example #13
0
        /// <summary>
        /// </summary>
        /// <returns>Arvore com os galhos:
        ///           6
        ///         /   \
        ///        3     5
        ///       /       \
        ///      2         0
        ///     /           \
        ///    1             \
        /// </returns>
        public override string ToString()
        {
            int qtdEspacosLado = 3 * TamanhoMaiorGalho - 1;
            int qtdEspacosMeio = 1;

            string arvore = string.Format("{0}{1}\n", espacos(qtdEspacosLado), Raiz.ToString());

            for (int i = 0; i < TamanhoMaiorGalho; i++)
            {
                qtdEspacosLado--;
                arvore += $"{espacos(qtdEspacosLado)}/{espacos(qtdEspacosMeio)}\\\n";
                qtdEspacosLado--;
                qtdEspacosMeio += 2 + (GalhoDireita.ObterNumero(i) ?? " ").Length - (GalhoEsquerda.ObterNumero(i) ?? " ").Length;
                arvore         += $"{espacos(qtdEspacosLado)}{GalhoEsquerda.ObterNumero(i) ?? "/"}{espacos(qtdEspacosMeio)}{GalhoDireita.ObterNumero(i) ?? "\\"}\n";
                qtdEspacosMeio += 2;
            }

            return(arvore);
Example #14
0
 // ----------------------------------------------------------------------------
 public void PostOrden()
 {
     if (Raiz != null)
     {
         // ----- Procesar hijo Izq
         if (SubArbolIzq != null)
         {
             SubArbolIzq.PostOrden();
         }
         // ----- Procesar hijo Der
         if (SubArbolDer != null)
         {
             SubArbolDer.PostOrden();
         }
         // ----- Procesar la raiz
         Console.WriteLine(Raiz.ToString());
     }
 }
Example #15
0
 // ----------------------------------------------------------------------------
 public CArbolBB SubArbol(object pRaiz)
 {
     if (EsVacio())
     {
         return(null);
     }
     else
     if (Raiz.Equals(pRaiz))
     {
         return(this);
     }
     else
     if (pRaiz.ToString().CompareTo(Raiz.ToString()) < 0)
     {
         return(SubArbolIzq != null?SubArbolIzq.SubArbol(pRaiz) : null);
     }
     else
     {
         return(SubArbolDer != null?SubArbolDer.SubArbol(pRaiz) : null);
     }
 }
Example #16
0
 // ----------------------------------------------------------------------------
 public CArbolBB Padre(object pRaiz)
 {
     if (EsVacio())
     {
         return(null);
     }
     else
     if (EsHijo(pRaiz))
     {
         return(this);
     }
     else
     if (pRaiz.ToString().CompareTo(Raiz.ToString()) < 0)
     {
         return(SubArbolIzq != null?SubArbolIzq.Padre(pRaiz) : null);
     }
     else
     {
         return(SubArbolDer != null?SubArbolDer.Padre(pRaiz) : null);
     }
 }
        /// <summary>
        /// Método para la creación del árbol basado en la notación postfija
        /// </summary>
        /// <param name="expresionPostfija"></param>
        public void CrearArbol(string expresionPostfija)
        {
            var pila          = new Stack <Nodo>(); //Pila que guardará momentanemente los nodos para ir formando en orden el árbol
            var contadorHojas = 1;

            while (expresionPostfija.Length != 0)
            {
                var nuevoNodo = new Nodo();

                if (!Operadores.Contains(expresionPostfija[0]) && expresionPostfija[0] != '#') //Si No es un operador y si NO es el estado de ACEPTACIÓN
                {
                    nuevoNodo.ItemExpresion = expresionPostfija[0].ToString();
                    nuevoNodo.NumNodo       = contadorHojas;
                    nuevoNodo.Follow        = new List <Nodo>();
                    nuevoNodo.EsHoja        = true;
                    contadorHojas++;

                    nuevoNodo.AsignarNulabilidad();

                    pila.Push(nuevoNodo);
                }
                else if (Operadores.Contains(expresionPostfija[0]) && expresionPostfija[0] != '#') //Si ES operador
                {
                    if (pila.Count >= 2 && expresionPostfija[0] != '*' && expresionPostfija[0] != '+')
                    {
                        nuevoNodo.ItemExpresion = expresionPostfija[0].ToString();

                        nuevoNodo.DrchNodo = pila.Pop();
                        nuevoNodo.IzqNodo  = pila.Pop();

                        nuevoNodo.AsignarNulabilidad();
                    }
                    else
                    {
                        nuevoNodo.ItemExpresion = expresionPostfija[0].ToString();

                        if (pila.Count > 0)
                        {
                            nuevoNodo.IzqNodo = pila.Pop();
                        }

                        nuevoNodo.AsignarNulabilidad();
                    }
                    pila.Push(nuevoNodo);
                }
                else if (expresionPostfija[0] == '#')
                {
                    nuevoNodo.ItemExpresion = expresionPostfija[0].ToString();
                    nuevoNodo.NumNodo       = contadorHojas;
                    nuevoNodo.EsHoja        = true;

                    nuevoNodo.AsignarNulabilidad();

                    Raiz          = pila.Pop();
                    Raiz.DrchNodo = nuevoNodo;
                    Raiz.AsignarNulabilidad();
                }

                expresionPostfija = expresionPostfija.Remove(0, 1);
            }
        }
Example #18
0
        public async Task <ActionResult <Raiz> > PostRaiz(Raiz raiz)
        {
            await _unitOfWork.Raiz.Add(raiz);

            return(CreatedAtAction("GetRaiz", new { id = raiz.raizlId }, raiz));
        }
Example #19
0
 public void ImprimeRaiz(Raiz raiz)
 {
     Console.Write("Raiz");
     raiz.Esquerda.Aceita(this);
 }
Example #20
0
 public string ParaAjusteTamanoCadena()
 {
     return($"{Raiz.ToString("0000000000;-000000000")}" + MetodosNecesarios.Separador.ToString() + $"{Order.ToString("0000000000;-000000000")}" + MetodosNecesarios.Separador.ToString() + $"{SiguientePosicion.ToString("0000000000;-000000000")}\r\n");
 }
Example #21
0
 public Form1()
 {
     NuevaRaiz = new Raiz();
     InitializeComponent();
     System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-AR");
 }
Example #22
0
        public Object traeLlamadas(ParseTreeNode raiz)
        {
            String eti = raiz.Term.Name;

            switch (eti)
            {
            case "LLAMADAID_OBJ":
            {
                if (raiz.ChildNodes.Count > 0)
                {
                    Accesos acceso = new Accesos(0, 0, this.clase);
                    acceso.SetArchivoOrigen(archivo);
                    foreach (ParseTreeNode n in raiz.ChildNodes)
                    {
                        Expresion ex = (Expresion)traeLlamadas(n);
                        if (ex != null)
                        {
                            acceso.AddExpresion(ex);
                        }
                    }
                    return(acceso);
                }
                break;
            }

            case "LLAMADA":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    if (raiz.ChildNodes.ElementAt(1).ToString().Equals("L_EXPRE"))
                    {
                        String  id    = raiz.ChildNodes.ElementAt(0).Token.Text.ToLower();    //MINUSCULAS
                        int     linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                        int     col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;
                        Llamada llam  = new Llamada(id, linea, col, this.clase);
                        llam.SetArchivoOrigen(archivo);
                        if (raiz.ChildNodes.ElementAt(1).ChildNodes.Count > 0)        //SI EL HIJO DERECHO TIENE MAS DE UN HIJO ENTONCES LO RECORRO COMO EXP
                        {
                            foreach (ParseTreeNode n in raiz.ChildNodes.ElementAt(1).ChildNodes)
                            {
                                Expresion aux = (Expresion)recorreExpresion(n); //LOS TOMO...
                                if (aux != null)                                //SI NO ES NULL...
                                {
                                    llam.AddExpresion(aux);                     //LO ANADO
                                }
                            }
                        }
                        return(llam);
                    }
                    else if (raiz.ChildNodes.ElementAt(1).ToString().Equals("DIMS"))
                    {
                        //NECESITO HACER LA EXPRESION PARA ACCESO A ARREGLO
                        // id + DIMS
                        String id    = raiz.ChildNodes.ElementAt(0).Token.Text.ToLower();
                        int    linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                        int    col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                        List <Expresion> expresiones = (List <Expresion>)getDimensiones(raiz.ChildNodes.ElementAt(1));

                        if (expresiones != null)
                        {
                            ValorArreglo val = new ValorArreglo(id, expresiones, linea, col, clase);
                            return(val);
                        }
                    }
                }
                else if (raiz.ChildNodes.Count == 3)
                {
                    if (raiz.ChildNodes.ElementAt(0).ToString().Contains("obtener") || raiz.ChildNodes.ElementAt(0).ToString().Contains("buscar"))
                    {
                        String id    = raiz.ChildNodes.ElementAt(0).Token.Text.ToLower();     //MINUSCULAS
                        int    linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                        int    col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                        Llamada llam = new Llamada(id, linea, col, this.clase);

                        ASTTreeExpresion ar  = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                        Expresion        uno = (Expresion)ar.ConstruyeASTExpresion();

                        ar = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(2), clase, archivo);
                        Expresion dos = (Expresion)ar.ConstruyeASTExpresion();

                        if (uno != null && dos != null)
                        {
                            llam.AddExpresion(uno);
                            llam.AddExpresion(dos);
                            return(llam);
                        }
                    }
                }
                break;
            }

            case "identificador":
            {
                int           linea = raiz.Token.Location.Line;
                int           col   = raiz.Token.Location.Column;
                String        id    = raiz.Token.Text.ToLower();//MINUSCULAS
                Identificador ide   = new Identificador(id, col, linea, this.clase);
                ide.SetArchivoOrigen(archivo);
                return(ide);
            }

            case "DECLARACION_OBJ":
            {
                if (raiz.ChildNodes.Count == 3)
                {
                    String           tipo       = (String)dameTipo(raiz.ChildNodes.ElementAt(1));
                    List <Expresion> parametros = new List <Expresion>();
                    foreach (ParseTreeNode nodo in raiz.ChildNodes.ElementAt(2).ChildNodes)
                    {
                        Expresion aux = (Expresion)recorreExpresion(nodo);
                        if (aux != null)
                        {
                            parametros.Add(aux);
                        }
                    }
                    if (tipo != null)
                    {
                        int         linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                        int         col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;
                        NuevoObjeto ob    = new NuevoObjeto(parametros, tipo, linea, col, this.clase);
                        ob.SetArchivoOrigen(archivo);
                        return(ob);
                    }
                }
                break;
            }

            case "DECLARACION_ARR":
            {
                if (raiz.ChildNodes.Count == 3)
                {
                    String           tipo        = (String)dameTipo(raiz.ChildNodes.ElementAt(1));//OBTENGO EL TIPO DEL ARREGLO
                    int              linea       = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int              col         = raiz.ChildNodes.ElementAt(0).Token.Location.Column;
                    List <Expresion> dimensiones = (List <Expresion>)getDimensiones(raiz.ChildNodes.ElementAt(2));      //OBTENGO LAS DIMENSIONES

                    if (tipo != null)
                    {
                        NuevoArreglo nuev = new NuevoArreglo(tipo, dimensiones, linea, col, clase);
                        return(nuev);
                    }
                }
                break;
            }

            case "OPCS_NUEVO":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int colum = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    NuevoListadoOpcs opcs = new NuevoListadoOpcs(this.clase.ToLower(), linea, colum);
                    return(opcs);
                }
                break;
            }

            case "FUN_CADENA":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    ASTTreeExpresion arbol = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                    Expresion        exp   = (Expresion)arbol.ConstruyeASTExpresion();

                    if (exp != null)
                    {
                        ACadena cad = new ACadena(exp, clase, linea, col);
                        return(cad);
                    }
                }
                break;
            }

            case "FUN_SUBCAD":
            {
                if (raiz.ChildNodes.Count == 4)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    ASTTreeExpresion arbol  = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                    Expresion        cadena = (Expresion)arbol.ConstruyeASTExpresion();

                    arbol = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(2), clase, archivo);
                    Expresion num1 = (Expresion)arbol.ConstruyeASTExpresion();

                    arbol = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(3), clase, archivo);
                    Expresion num2 = (Expresion)arbol.ConstruyeASTExpresion();

                    if (cadena != null && num1 != null && num2 != null)
                    {
                        SubCade s = new SubCade(cadena, num1, num2, linea, col, clase);
                        return(s);
                    }
                }
                break;
            }

            case "FUN_POSCAD":
            {
                if (raiz.ChildNodes.Count == 3)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    ASTTreeExpresion arbol  = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                    Expresion        cadena = (Expresion)arbol.ConstruyeASTExpresion();

                    arbol = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(2), clase, archivo);
                    Expresion posicion = (Expresion)arbol.ConstruyeASTExpresion();

                    if (cadena != null && posicion != null)
                    {
                        PosCade posca = new PosCade(cadena, posicion, clase, linea, col);
                        return(posca);
                    }
                }
                break;
            }

            case "FUN_BOOLEAN":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    ASTTreeExpresion expr      = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                    Expresion        expresion = (Expresion)expr.ConstruyeASTExpresion();

                    if (expresion != null)
                    {
                        return(new ABooleano(expresion, clase, linea, col));
                    }
                }
                break;
            }

            case "FUN_ENTERO":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    ASTTreeExpresion expr      = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                    Expresion        expresion = (Expresion)expr.ConstruyeASTExpresion();

                    if (expresion != null)
                    {
                        return(new AEntero(expresion, clase, linea, col));
                    }
                }
                break;
            }

            case "FUN_TAM":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    ASTTreeExpresion expr      = new ASTTreeExpresion(raiz.ChildNodes.ElementAt(1), clase, archivo);
                    Expresion        expresion = (Expresion)expr.ConstruyeASTExpresion();

                    if (expresion != null)
                    {
                        FunTam f = new FunTam(expresion, clase, linea, col);
                        return(f);
                    }
                }
                break;
            }

            case "FUN_RANDOM":
            {
                if (raiz.ChildNodes.Count == 1)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    FunRandom r = new FunRandom(clase, linea, col);
                    return(r);
                }
                else if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    List <Expresion> exp = new List <Expresion>();

                    foreach (ParseTreeNode nodo in raiz.ChildNodes.ElementAt(1).ChildNodes)
                    {
                        Expresion aux = (Expresion)recorreExpresion(nodo);
                        if (aux != null)
                        {
                            exp.Add(aux);
                        }
                    }

                    FunRandom r = new FunRandom(exp, clase, linea, col);
                    return(r);
                }
                break;
            }

            case "FUN_MIN":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;
                    if (raiz.ChildNodes.ElementAt(1).ToString().Equals("L_EXPRE"))
                    {
                        List <Expresion> expresiones = new List <Expresion>();
                        foreach (ParseTreeNode nodo in raiz.ChildNodes.ElementAt(1).ChildNodes)
                        {
                            Expresion exp = (Expresion)recorreExpresion(nodo);
                            if (exp != null)
                            {
                                expresiones.Add(exp);
                            }
                        }

                        ///AQUI RETORNO
                        FunMin f = new FunMin(expresiones, clase, linea, col);
                        return(f);
                    }
                    else
                    {
                        String idArreglo = raiz.ChildNodes.ElementAt(1).Token.Text.ToLower();
                        FunMin f         = new FunMin(idArreglo.ToLower(), clase, linea, col);
                        return(f);
                    }
                }
                break;
            }

            case "FUN_MAX":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;
                    if (raiz.ChildNodes.ElementAt(1).ToString().Equals("L_EXPRE"))
                    {
                        List <Expresion> expresiones = new List <Expresion>();
                        foreach (ParseTreeNode nodo in raiz.ChildNodes.ElementAt(1).ChildNodes)
                        {
                            Expresion exp = (Expresion)recorreExpresion(nodo);
                            if (exp != null)
                            {
                                expresiones.Add(exp);
                            }
                        }

                        /// AQUI RETORNO
                        FunMax f = new FunMax(expresiones, clase, linea, col);
                        return(f);
                    }
                    else
                    {
                        String idArreglo = raiz.ChildNodes.ElementAt(1).Token.Text.ToLower();
                        FunMax f         = new FunMax(idArreglo.ToLower(), clase, linea, col);
                        return(f);
                    }
                }
                break;
            }

            case "FUN_POW":
            {
                if (raiz.ChildNodes.Count == 3)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion bas = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));
                    Expresion pot = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(2));

                    if (bas != null && pot != null)
                    {
                        FunPow po = new FunPow(bas, pot, clase, linea, col);
                        return(po);
                    }
                }
                break;
            }

            case "FUN_LOG":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        Logaritmo l = new Logaritmo(exp, clase, linea, col);
                        return(l);
                    }
                }
                break;
            }

            case "FUN_LOG10":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        LogTen l = new LogTen(exp, clase, linea, col);
                        return(l);
                    }
                }
                break;
            }

            case "FUN_ABS":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        FunAbs abs = new FunAbs(exp, clase, linea, col);
                        return(abs);
                    }
                }
                break;
            }

            case "FUN_SIN":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        Seno s = new Seno(exp, clase, linea, col);
                        return(s);
                    }
                }
                break;
            }

            case "FUN_COS":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        Coseno c = new Coseno(exp, clase, linea, col);
                        return(c);
                    }
                }
                break;
            }

            case "FUN_TAN":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        Tangente t = new Tangente(exp, clase, linea, col);
                        return(t);
                    }
                }
                break;
            }

            case "FUN_SQRT":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        Raiz r = new Raiz(exp, clase, linea, col);
                        return(r);
                    }
                }
                break;
            }

            case "FUN_PI":
            {
                if (raiz.ChildNodes.Count == 1)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;
                    Pi  p     = new Pi(clase, linea, col);
                    return(p);
                }
                break;
            }

            case "FUN_HOY":
            {
                if (raiz.ChildNodes.Count == 1)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    FunHoy hoy = new FunHoy(clase, linea, col);
                    return(hoy);
                }
                break;
            }

            case "FUN_AHORA":
            {
                if (raiz.ChildNodes.Count == 1)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    FunAhora ahora = new FunAhora(clase, linea, col);
                    return(ahora);
                }
                break;
            }

            case "FUN_AFECHA":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        FunAFecha r = new FunAFecha(exp, clase, linea, col);
                        return(r);
                    }
                }
                break;
            }

            case "FUN_TOHORA":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        FunToHora f = new FunToHora(exp, clase, linea, col);
                        return(f);
                    }
                }
                break;
            }

            case "FUN_TOFECHAHORA":
            {
                if (raiz.ChildNodes.Count == 2)
                {
                    int linea = raiz.ChildNodes.ElementAt(0).Token.Location.Line;
                    int col   = raiz.ChildNodes.ElementAt(0).Token.Location.Column;

                    Expresion exp = (Expresion)recorreExpresion(raiz.ChildNodes.ElementAt(1));

                    if (exp != null)
                    {
                        FunFechaHora f = new FunFechaHora(exp, clase, linea, col);
                        return(f);
                    }
                }
                break;
            }
            }
            return(null);
        }
Example #23
0
 // ----------------------------------------------------------------------------
 public virtual void Eliminar(Object pRaiz)
 {
     if (EsVacio())
     {
         Console.WriteLine("ERROR. Elemento no encontrado...");
     }
     else
     {
         // ----- Verificar si la raiz es el elemento que se desea eliminar
         if (pRaiz.Equals(Raiz))
         {
             // Si no tiene hijos, eliminar la raiz o una hoja
             if (SubArbolIzq == null && SubArbolDer == null)
             {
                 Raiz = null;
             }
             else // árbol tiene por lo menos un hijo
             if (SubArbolIzq == null)     // ----- Solo tiene hijo derecho
             {
                 Raiz        = SubArbolDer.Raiz;
                 SubArbolIzq = SubArbolDer.SubArbolIzq;
                 SubArbolDer = SubArbolDer.SubArbolDer;
             }
             else
             if (SubArbolDer == null)         // ----- Solo tiene hijo izquierdo
             {
                 Raiz        = SubArbolIzq.Raiz;
                 SubArbolDer = SubArbolIzq.SubArbolDer;
                 SubArbolIzq = SubArbolIzq.SubArbolIzq;
             }
             else         // Tiene ambos hijos
             {
                 Raiz = SubArbolDer.Minimo();
                 SubArbolDer.Eliminar(Raiz);
             }
         }
         else
         // ----- Verificar si el elemento a eliminar esta en el hijo Izq
         if (pRaiz.ToString().CompareTo(Raiz.ToString()) < 0)
         {
             if (SubArbolIzq != null)
             {
                 SubArbolIzq.Eliminar(pRaiz);
             }
         }
         else
         // ----- Elemento a eliminar esta en el hijo Der
         if (SubArbolDer != null)
         {
             SubArbolDer.Eliminar(pRaiz);
         }
         // Verificar si los hijos son hojas vacias
         if (SubArbolIzq != null && SubArbolIzq.EsVacio())
         {
             SubArbolIzq = null;
         }
         if (SubArbolDer != null && SubArbolDer.EsVacio())
         {
             SubArbolDer = null;
         }
     }
 }