コード例 #1
0
ファイル: IngresarNodoBo.cs プロジェクト: iordenes/PruebaBST
        /// <summary>
        /// Método que ingresa el listado Inicial
        /// </summary>
        /// <param name="lstParametros"></param>
        /// <returns></returns>
        #region [Procesar]
        public int Procesar(IList <int> lstParametros)
        {
            var arbol   = new List <ArbolEntity>();
            int i       = 0;
            int idPadre = 0;
            int nivel   = 0;

            foreach (var item in lstParametros)
            {
                int ultimoNivel = arbol.Any() ? arbol.Max(x => x.Nivel) : 0;
                if (!arbol.Any())
                {
                    arbol.Add(ArbolMapper.ToEntity(i, item, null, DireccionEnum.Derecha, nivel));
                    nivel++;
                }
                else
                {
                    foreach (var itemNodo in arbol)
                    {
                        if (itemNodo.NumeroRaiz < item)
                        {
                            if (ultimoNivel == itemNodo.Nivel)
                            {
                                arbol.Add(ArbolMapper.ToEntity(i, item, idPadre, DireccionEnum.Derecha, nivel));
                                nivel++;
                                break;
                            }
                        }
                        else
                        {
                            if (ultimoNivel == itemNodo.Nivel)
                            {
                                arbol.Add(ArbolMapper.ToEntity(i, item, idPadre, DireccionEnum.Izquierda, nivel));
                                nivel++;
                                break;
                            }
                        }
                    }
                }
                idPadre = i;
            }
            return(0);
        }
コード例 #2
0
ファイル: ArbolDao.cs プロジェクト: iordenes/PruebaBST
        /// <summary>
        /// Método que inserta un arbol (Nodo)
        /// </summary>
        /// <param name="idPadre"></param>
        /// <param name="numeroRaiz"></param>
        /// <returns></returns>
        #region [Insertar Arbol]
        public bool InsertarArbol(int idPadre, int numeroRaiz)
        {
            try
            {
                var arbolCache = (IList <ArbolEntity>)cache["arbol"];
                var idMaximo   = arbolCache.Max(x => x.Id);

                arbolCache.Add(ArbolMapper.ToEntity(idMaximo, numeroRaiz, idPadre, DireccionEnum.Derecha, 0));

                cache["arbol"] = arbolCache;

                return(true);
            }
            catch (Exception e)
            {
                //Log
                throw new Exception(e.Message);
            }
        }