Пример #1
0
        public void regresarActivo(string idActivo)
        {
            Rentas renta = new Rentas();

            renta.idActivo = idActivo;
            arbolB.setRenta(renta);
        }
        public NodoArbolB(Object objeto)
        {
            Rentas renta = (Rentas)objeto;


            llaves[0] = renta;
        }
Пример #3
0
        public void Lista(Rentas renta, NodoArbolB nodo)
        {
            if (nodo != null)
            {
                if (nodo.punteros != null)
                {
                    for (int i = 0; i < nodo.punteros.Length - 1; i++)
                    {
                        if (nodo.punteros[i] != null)
                        {
                            Lista(renta, nodo.punteros[i]);
                        }
                    }
                }

                for (int j = 0; j < nodo.llaves.Length - 1; j++)
                {
                    if (nodo.llaves[j] != null)
                    {
                        if (nodo.llaves[j].idActivo.Equals(renta.idActivo))
                        {
                            Console.WriteLine("Raiz: " + nodo.llaves[j].identificador + " Activo:" + nodo.llaves[j].idActivo);
                            lstnodos.Add(nodo.llaves[j]);
                        }
                    }
                }
            }
        }
Пример #4
0
        //NODOS CON PRECEDENCIA
        public NodoArbolB PrecedenciaNodo(Rentas renta, NodoArbolB nodo)
        {
            int i = 1;

            while (i <= nodo.ULlave)
            {
                if (nodo.llaves[i - 1].identificador.Equals(renta.identificador))
                {
                    nodo = nodo.punteros[i];
                    break;
                }
                i++;
            }
            while (true)
            {
                if (nodo.hoja)
                {
                    return(nodo);
                }
                else
                {
                    nodo = nodo.punteros[0];
                }
            }
        }
Пример #5
0
        //OBTENER VALOR DE ATRIBUTO KEY (MOSTRAR)
        //public int get(int llave)
        //{
        //    int k = 0;
        //    if (this.existe(llave))
        //    {
        //        NodoArbolB nodo = this.buscar(llave, this.raiz);
        //        for (int i = 0; i < 4; i++)
        //        {
        //            if (nodo.llaves[i] == llave)
        //            {
        //                k = nodo.llaves[i];
        //                break;
        //            }
        //        }
        //    }
        //    return k;
        //}

        //OBETNER VALOR DE ATRIBUTO KEY REMPLZAR CON ATRIBUTO N (MODIFICAR)
        public void set(Rentas renta, Rentas Reemplazo)
        {
            if (this.existe(renta))
            {
                NodoArbolB nodo = this.buscar(renta, this.raiz);
                this.ReemplazarLlave(nodo, renta, Reemplazo);
            }
        }
Пример #6
0
        public string eliminar(string idActivo)
        {
            Rentas renta = new Rentas();

            renta.idActivo = idActivo;
            arbolB.Remover(renta);
            arbolB.printGraphviz();
            return("Transacciones eliminadas");
        }
Пример #7
0
 //METODO QUE VRIFICAR QUE EXISTA UN ATRIBUTO KEY
 public Boolean existe(Rentas renta)
 {
     if (buscar(renta, this.raiz) != null)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #8
0
        //ALGORITMO PARA REEMPLAZAR
        public void ReemplazarLlave(NodoArbolB nodo, Rentas renta, Rentas renta2)
        {
            int i = 1;

            while (i <= nodo.ULlave)
            {
                if (nodo.llaves[i - 1].identificador.Equals(renta.identificador))
                {
                    nodo.llaves[i - 1] = renta2;
                    break;
                }
                i++;
            }
        }
Пример #9
0
        public string insertar(string idrenta, string idactivo, string nombre, string descripcion, string user, string empresa, string departamento, string fecha, string tiempo)
        {
            Rentas renta = new Rentas();

            renta.identificador = idrenta;
            renta.idActivo      = idactivo;
            renta.usuario       = user;
            renta.empresa       = empresa;
            renta.departamento  = departamento;
            renta.descripcion   = descripcion;
            renta.nombre        = nombre;
            renta.fecha         = fecha;
            renta.tiempo        = tiempo;
            renta.rentado       = true;

            arbolB.insertar(renta);
            arbolB.printGraphviz();

            return("Agregado");
        }
Пример #10
0
        public List <string> ActivosActivos(string usuario, string empresa, string departamento)
        {
            Rentas rent = new Rentas();

            rent.usuario      = usuario;
            rent.empresa      = empresa;
            rent.departamento = departamento;

            ListaActivo(rent, raiz);


            List <string> auxlista = new List <string>();

            for (int i = 0; i < lstactivos.Count; i++)
            {
                Rentas aux = lstactivos[i];
                auxlista.Add(aux.idActivo + "," + aux.nombre + "," + aux.descripcion);
            }



            return(auxlista);
        }
Пример #11
0
        //METODO DE BUSQUEDA , PERMITIRA BUSCAR ELEMENTOS EN EL ARBOL
        //ALGORITMO REURSIVO ESENCIAL PARA LA INSERCION , ELIMINACION


        //METODO DE BUSQUEDA , PERMITIRA BUSCAR ELEMENTOS EN EL ARBOL
        //ALGORITMO REURSIVO ESENCIAL PARA LA INSERCION , ELIMINACION
        private NodoArbolB buscar(Rentas renta, NodoArbolB node)
        {
            if (node != null)
            {
                int i = 1;
                while (i <= node.ULlave && (string.Compare(node.llaves[i - 1].identificador, renta.identificador) < 0))
                {
                    i++;
                }
                if (i > node.ULlave || (string.Compare(node.llaves[i - 1].identificador, renta.identificador) > 0))
                {
                    return(buscar(renta, node.punteros[i - 1]));
                }
                else
                {
                    return(node);
                }
            }
            else
            {
                return(null);
            }
        }
Пример #12
0
        public void setRenta(Rentas renta, NodoArbolB nodo)
        {
            if (nodo.punteros != null)
            {
                for (int i = 0; i < nodo.punteros.Length - 1; i++)
                {
                    if (nodo.punteros[i] != null)
                    {
                        setRenta(renta, nodo.punteros[i]);
                    }
                }
            }

            for (int j = 0; j < nodo.llaves.Length - 1; j++)
            {
                if (nodo.llaves[j] != null)
                {
                    if (nodo.llaves[j].idActivo.Equals(renta.idActivo) && nodo.llaves[j].rentado == true)
                    {
                        nodo.llaves[j].rentado = false;
                    }
                }
            }
        }
Пример #13
0
        public void ListaActivo(Rentas renta, NodoArbolB nodo)
        {
            if (nodo.punteros != null)
            {
                for (int i = 0; i < nodo.punteros.Length - 1; i++)
                {
                    if (nodo.punteros[i] != null)
                    {
                        ListaActivo(renta, nodo.punteros[i]);
                    }
                }
            }

            for (int j = 0; j < nodo.llaves.Length - 1; j++)
            {
                if (nodo.llaves[j] != null)
                {
                    if (nodo.llaves[j].usuario.Equals(renta.usuario) && nodo.llaves[j].empresa.Equals(renta.empresa) && nodo.llaves[j].departamento.Equals(renta.departamento) && nodo.llaves[j].rentado == true)
                    {
                        lstactivos.Add(nodo.llaves[j]);
                    }
                }
            }
        }
Пример #14
0
        //ALGORITMO QUE ELMININA KEYS EN NODOS HOJA
        public void EliminarHoja(NodoArbolB nodo, Rentas renta)
        {
            int i = 0;

            while (i < nodo.ULlave)
            {
                if (nodo.llaves[i].identificador.Equals(renta.identificador))
                {
                    while (i < nodo.ULlave - 1)
                    {
                        nodo.llaves[i] = nodo.llaves[i + 1];

                        i++;
                    }
                    nodo.llaves[nodo.ULlave - 1] = null;

                    nodo.ULlave--;
                }
                else
                {
                    i++;
                }
            }
        }
Пример #15
0
        //ALGORITMO DE INSERCION
        public void insertar(Rentas renta)
        {
            if (this.raiz == null)
            {
                this.raiz = new NodoArbolB(renta);
                return;
            }
            NodoArbolB nodo = raiz;

            while (nodo.hoja == false)
            {
                int i = 1;
                while (i <= nodo.ULlave && (nodo.llaves[i - 1].identificador.CompareTo(renta.identificador)) != 1)
                {
                    i++;
                }
                nodo = nodo.punteros[i - 1];
            }

            Boolean    posInLeaf = true;
            NodoArbolB node1     = null;
            NodoArbolB node2     = null;

            while (true)
            {
                int i = 1;
                while (i <= nodo.ULlave && (nodo.llaves[i - 1].identificador.CompareTo(renta.identificador)) != 1)
                {
                    i++;
                }

                if (i <= nodo.ULlave)
                {
                    int finalPointer = nodo.ULlave - 1;
                    while (finalPointer >= i - 1)
                    {
                        nodo.llaves[finalPointer + 1] = nodo.llaves[finalPointer];

                        nodo.punteros[finalPointer + 2] = nodo.punteros[finalPointer + 1];
                        finalPointer--;
                    }
                }

                nodo.llaves[i - 1] = renta;

                nodo.ULlave = nodo.ULlave + 1;

                if (node1 != null && node2 != null)
                {
                    nodo.punteros[i - 1] = node1;
                    nodo.punteros[i]     = node2;

                    node1 = null;
                    node2 = null;
                }

                int order = 6;
                //Máximo de claves permitidas en un Árbol B = m-1
                if (nodo.ULlave < order - 1)
                {
                    return;
                }
                else
                {
                    int posInMiddleKey = (order / 2) - 1;

                    renta = nodo.llaves[posInMiddleKey];


                    node1 = nodo;
                    node2 = new NodoArbolB();

                    if (posInLeaf)
                    {
                        node1.hoja = true;
                        node2.hoja = true;
                    }
                    else
                    {
                        node1.hoja = false;
                        node2.hoja = false;
                    }

                    node1.llaves[posInMiddleKey] = null;

                    node1.ULlave = (order / 2) - 1;
                    node2.ULlave = (order / 2) - 1;
                    int posInNode1 = posInMiddleKey + 1;
                    int posInNode2 = 0;
                    while (posInNode1 < order - 1)
                    {
                        node2.llaves[posInNode2] = node1.llaves[posInNode1];

                        node1.llaves[posInNode1] = null;


                        node2.punteros[posInNode2] = node1.punteros[posInNode1];
                        if (node2.punteros[posInNode2] != null)
                        {
                            node2.punteros[posInNode2].Padre = node2;
                        }

                        node1.punteros[posInNode1] = null;

                        //----------------------------------------------

                        posInNode1++;
                        posInNode2++;

                        if (posInNode1 == order - 1)
                        {
                            node2.punteros[posInNode2] = node1.punteros[posInNode1];
                            if (node2.punteros[posInNode2] != null)
                            {
                                node2.punteros[posInNode2].Padre = node2;
                            }

                            node1.punteros[posInNode1] = null;
                        }
                    }

                    if (nodo == this.raiz)
                    {
                        NodoArbolB auxRaiz = new NodoArbolB(renta);
                        auxRaiz.hoja        = false;
                        auxRaiz.punteros[0] = node1;
                        auxRaiz.punteros[1] = node2;

                        node1.Padre = auxRaiz;
                        node2.Padre = auxRaiz;

                        this.raiz = auxRaiz;
                        return;
                    }
                    else
                    {
                        nodo        = nodo.Padre;
                        node2.Padre = node1.Padre;
                        posInLeaf   = false;
                    }
                }
            }
        }
Пример #16
0
 public void setRenta(Rentas re)
 {
     setRenta(re, raiz);
 }
Пример #17
0
        //    for (int i = 0; i < nodo.punteros.Length - 1; i++)
        //    {
        //        if (nodo.punteros[i] != null)
        //        {
        //            for (int h = 0; h < nodo.punteros[i].punteros.Length - 1; h++)
        //            {
        //                if (nodo.punteros[i].punteros[h] != null)
        //                {
        //                    Lista(renta, nodo.punteros[i]);
        //                }
        //                else
        //                {
        //                    for (int j = 0; j < nodo.llaves.Length - 1; j++)
        //                    {
        //                        if (nodo.punteros[i].llaves[j] != null)
        //                        {
        //                            if (nodo.punteros[i].llaves[j].idActivo.Equals(renta.idActivo))
        //                            {
        //                                Console.WriteLine("Raiz: " + nodo.punteros[i].llaves[j].identificador + " Activo:" + nodo.punteros[i].llaves[j].idActivo);
        //                                lstnodos.Add(nodo.punteros[i].llaves[j]);

        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //    }
        //}



        //for (int i = 0; i < nodo.punteros.Length - 1; i++)
        //{
        //    if (nodo.punteros[i] != null)
        //    {
        //        if (nodo.punteros[i].punteros != null)
        //        {
        //            Lista(renta, nodo.punteros[i]);
        //        }
        //        for (int j = 0; j < nodo.llaves.Length - 1; j++)
        //        {
        //            if (nodo.punteros[i].llaves[j] != null)
        //            {
        //                if (nodo.punteros[i].llaves[j].idActivo.Equals(renta.idActivo))
        //                {
        //                    Console.WriteLine("Raiz: " + nodo.punteros[i].llaves[j].identificador + " Activo:" + nodo.punteros[i].llaves[j].idActivo);
        //                    lstnodos.Add(nodo.punteros[i].llaves[j]);

        //                }

        //            }
        //        }
        //    }
        //}



        //METODO ELIMINAR , ELIMINA ID EN EL ARBOL SEGUN PARAMETRO ENVIADO
        public void Remover(Rentas renta)
        {
            //BUSCA LA CLAVE

            Lista(renta, this.raiz);

            for (int i = 0; i < lstnodos.Count; i++)
            {
                NodoArbolB nodo = buscar(lstnodos[i], this.raiz);

                if (nodo != null)
                {
                    //ELIMINACION SI Y SOLO SI EL NODO NO ES HOJA
                    if (nodo.hoja == false)
                    {
                        NodoArbolB hoja        = PrecedenciaNodo(lstnodos[i], nodo);
                        Rentas     presedencia = hoja.llaves[0];
                        ReemplazarLlave(nodo, lstnodos[i], presedencia);
                        nodo = hoja;
                        EliminarHoja(hoja, presedencia);
                    }
                    else
                    {
                        //ELIMINACION NODO EN HOJA
                        EliminarHoja(nodo, lstnodos[i]);
                    }

                    //ALGORITMO QUE SE MANTIENE EJECUTANDO DURANTE LA ELIMINACION
                    //INSTRUCCIONES QUE CREAN NUEVAS RAICES, COMBINAN , MUEVEN IZQ DER EN CASO QUE SE ELIMINO
                    //NODOS EN LOS CUALES SE REQUIERE RESTRUCTURAR EL ARBOL ARMANDO NUEVAS PAGINAS
                    while (true)
                    {
                        if (VerificarMinimo(nodo))
                        {
                            break;
                        }
                        else if (derecha(nodo) != null && derecha(nodo).ULlave > 2)
                        {
                            TomardeDerecha(nodo);
                            break;
                        }
                        else if (izquierda(nodo) != null && izquierda(nodo).ULlave > 2)
                        {
                            TomardeIzquierda(nodo);
                            break;
                        }
                        else if (nodo.Padre == this.raiz)
                        {
                            if (nodo.Padre.ULlave == 1)
                            {
                                if (derecha(nodo) != null)
                                {
                                    NuevaRaiz(nodo, derecha(nodo));
                                }
                                else if (izquierda(nodo) != null)
                                {
                                    NuevaRaiz(izquierda(nodo), nodo);
                                }
                            }
                            else
                            {
                                combinar(nodo);
                            }
                            break;
                        }
                        else
                        {
                            combinar(nodo);
                            nodo = nodo.Padre;
                        }
                    }
                }
            }
        }