コード例 #1
0
ファイル: Nodo.cs プロジェクト: Jocagi/EDI
        public Nodo[] Split()
        {
            if (Llaves.Count != 2)
            {
                throw new InvalidOperationException(string.Format("This node has {0} Llaves, can only split a 2 Llaves node", Llaves.Count));
            }


            //TO DO: Hacer que nodo derecho obtenga todas la llaves a la derecha

            //Nodo derecho
            Nodo newRight = new Nodo(Llaves[1]);

            //inicia en la mitad y recorre valores hasta el final
            for (int x = 2; x < Hijos.Count; x++)
            {
                newRight.Hijos.Add(this.Hijos[x]);
            }


            //Remover valores presentes en nodo derecho
            for (int x = Hijos.Count - 1; x >= 2; x--)
            {
                this.Hijos.RemoveAt(x);
            }

            for (int x = 1; x < Llaves.Count; x++)
            {
                Llaves.RemoveAt(x);
            }

            //retorna vector con nodo izquierdo y derecho
            return(new Nodo[] { this, newRight });
        }
コード例 #2
0
        public Node[] Dividir()
        {
            if (Llaves.Count <= 2)
            {
                //No se puede dividir en 2 nodos por que aun hay espacio
            }

            Node Derechonuevo = new Node(Llaves[1]);

            for (int x = 2; x < Hijos.Count; x++) //Agrega los nodos a el nuevo nodo
            {
                Derechonuevo.Hijos.Add(this.Hijos[x]);
            }

            for (int x = Hijos.Count - 1; x >= 2; x--) //Elimina el nodo anterior
            {
                this.Hijos.RemoveAt(x);
            }

            for (int x = 1; x < Llaves.Count; x++)
            {
                Llaves.RemoveAt(x);
            }

            return(new Node[] { this, Derechonuevo });
        }
コード例 #3
0
        internal void SepararNodo(string llave, T dato, int hijoDerecho, Nodo <T> nuevoNodo, ref string llavePorSubir, ref T datoPorSubir)
        {
            if (!Lleno)
            {
                throw new Exception("Uno nodo solo puede separarse si está lleno");
            }
            Llaves.Add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
            Datos.Add(dato);
            Hijos.Add(Utilidades.apuntadoVacio);
            AgregarDato(llave, dato, hijoDerecho, false);
            int mitad = (Orden / 2);

            llavePorSubir = Utilidades.FormatearLlave(Llaves[mitad]);
            datoPorSubir  = Datos[mitad];
            Llaves[mitad] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            int j = 0;

            for (int i = mitad + 1; i < Llaves.Count; i++)
            {
                nuevoNodo.Llaves[j] = Llaves[i];
                nuevoNodo.Datos[j]  = Datos[i];
                Llaves[i]           = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
                j++;
            }
            j = 0;
            for (int i = mitad + 1; i < Hijos.Count; i++)
            {
                nuevoNodo.Hijos[j] = Hijos[i];
                Hijos[i]           = Utilidades.apuntadoVacio;
                j++;
            }
            Llaves.RemoveAt(Llaves.Count - 1);
            Datos.RemoveAt(Datos.Count - 1);
            Hijos.RemoveAt(Hijos.Count - 1);
        }
コード例 #4
0
ファイル: Nodo.cs プロジェクト: Jocagi/EDI
        public Medicamento Pop(int posicion)
        {
            if (posicion < Llaves.Count)
            {
                Medicamento valor = Llaves[posicion];
                Llaves.RemoveAt(posicion);

                return(valor);
            }

            return(null);
        }
コード例 #5
0
        public string Remover(int pos)
        {
            if (Llaves.Count > 1)//Solo se puede si hay mas de una llave, si no se quedaria vacio
            {
                if (pos < Llaves.Count)
                {
                    string temp = Llaves[pos];
                    Llaves.RemoveAt(pos);
                    return(temp);
                }
            }

            return(null);
        }
コード例 #6
0
ファイル: NodoB.cs プロジェクト: hermask8/Proyecto
        internal void SepararNodo(string llave, T dato, int hijoDerecho, NodoB <T> nuevoNodo, ref string llavePorSubir, ref T datoPorSubir)
        {
            if (!Lleno)
            {
                throw new Exception("Uno nodo solo puede separarse si está lleno");
            }

            // Incrementar el tamaño de las listas en una posición
            Llaves.Add("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
            Datos.Add(dato);
            Hijos.Add(Utilidades.ApuntadorVacio);

            // Agregar los nuevos elementos en orden
            AgregarDato(llave, dato, hijoDerecho, false);

            // Obtener los valores a subir
            int mitad = (Orden / 2);

            llavePorSubir = Llaves[mitad];
            datoPorSubir  = Datos[mitad];
            Llaves[mitad] = "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";

            // Llenar las llaves y datos que pasan al nuevo nodo
            int j = 0;

            for (int i = mitad + 1; i < Llaves.Count; i++)
            {
                nuevoNodo.Llaves[j] = Llaves[i];
                nuevoNodo.Datos[j]  = Datos[i];
                Llaves[i]           = "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
                j++;
            }

            // Llenar los hijos que pasan al nuevo nodo
            j = 0;
            for (int i = mitad + 1; i < Hijos.Count; i++)
            {
                nuevoNodo.Hijos[j] = Hijos[i];
                Hijos[i]           = Utilidades.ApuntadorVacio;
                j++;
            }
            Llaves.RemoveAt(Llaves.Count - 1);
            Datos.RemoveAt(Datos.Count - 1);
            Hijos.RemoveAt(Hijos.Count - 1);
        }
コード例 #7
0
ファイル: Nodo.cs プロジェクト: AxelRdz240899/SMBD-Axel
        public bool EliminaDatoEnHoja(int Clave)
        {
            if (Llaves.Contains(Clave))
            {
                int  Indice  = Llaves.IndexOf(Clave);
                long SigNodo = DireccionLlaves[Arbol.GradoArbol - 1];
                DireccionLlaves[Arbol.GradoArbol - 1] = (long)-1;

                Llaves.RemoveAt(Indice);
                DireccionLlaves.RemoveAt(Indice);
                Llaves.Add(-1);
                DireccionLlaves.Add(SigNodo);
                return(true);
            }
            else
            {
                return(false);
            }
        }