Exemplo n.º 1
0
    public NodoMatriz getNodo(String nombre)
    {
        NodoMatriz nodo = null;
        Encabezado e    = this.Filas.Cabeza;

        while (e != null)
        {
            nodo = e.Acceso;
            while (nodo != null)
            {
                if (String.Compare(nodo.Nave.Nombre, nombre) == 0)
                {
                    break;
                }
                nodo = nodo.Derecha;
            }
            if (nodo != null)
            {
                break;
            }
            e = e.Siguiente;
        }

        return(nodo);
    }
Exemplo n.º 2
0
        private int getProducto(NodoMatriz fila, NodoMatriz columna)
        {
            int suma = 0;

            while (fila != null)
            {
                suma   += (fila.getDato() * columna.getDato());
                fila    = fila.getDerecha();
                columna = columna.getAbajo();
            }

            return(suma);
        }
Exemplo n.º 3
0
    public NodoMatriz getNodo(int fila, int columna)
    {
        NodoMatriz nodo = null;
        Encabezado f    = this.Filas.getEncabezado(fila);

        if (f != null)
        {
            nodo = f.Acceso;
            while (nodo != null)
            {
                if (nodo.Columna == columna)
                {
                    break;
                }
                nodo = nodo.Derecha;
            }
        }
        return(nodo);
    }
Exemplo n.º 4
0
    //*****************************************METODOS DE LA MATRIZ*****************************************

    public void Insertar(int fila, int columna, String nombre, String nickname)
    {
        NodoMatriz nuevo = new NodoMatriz(nombre, nickname, fila, columna);
        Matriz     m     = this;

        //SELECCIONANDO NIVEL DONDE SE INSERTARA
        switch (nuevo.Nave.Nivel)
        {
        case 0:
            if (m.Anterior == null)
            {
                //CREANDO NIVEL 0
                m.Anterior = new Matriz(0);
                m          = m.Anterior;
            }
            else
            {
                m = m.Anterior;
            }
            break;

        case 1:
            break;

        case 2:
            if (m.Siguiente == null)
            {
                //CREANDO NIVEL 2
                m.Siguiente = new Matriz(2);
                m           = m.Siguiente;
            }
            else
            {
                m = m.Siguiente;
            }
            break;

        case 3:
            if (m.Siguiente == null)
            {
                //CREANDO NIVEL 2
                m.Siguiente = new Matriz(2);
                m           = m.Siguiente;
                //CREANDO NIVEL 3
                m.Siguiente = new Matriz(3);
                m           = m.Siguiente;
            }
            else
            {
                //YA EXISTE NIVEL 2
                m = m.Siguiente;
                if (m.Siguiente == null)
                {
                    //CREANDO NIVEL 3
                    m.Siguiente = new Matriz(3);
                    m           = m.Siguiente;
                }
                else
                {
                    m = m.Siguiente;
                }
            }
            break;

        default:
            break;
        }


        //INSERTANDO EN FILAS
        Encabezado f = m.Filas.getEncabezado(fila);

        if (f == null)
        {
            m.Filas.Insertar(fila);
            f        = m.Filas.getEncabezado(fila);
            f.Acceso = nuevo;
        }
        else
        {
            if (nuevo.Columna < f.Acceso.Columna)
            {
                f.Acceso.Izquierda = nuevo;
                nuevo.Derecha      = f.Acceso;
                f.Acceso           = nuevo;
            }
            else
            {
                NodoMatriz aux = f.Acceso;
                while (aux.Derecha != null)
                {
                    if (nuevo.Columna < aux.Derecha.Columna)
                    {
                        nuevo.Derecha         = aux.Derecha;
                        nuevo.Izquierda       = aux;
                        aux.Derecha.Izquierda = nuevo;
                        aux.Derecha           = nuevo;
                        break;
                    }
                    aux = aux.Derecha;
                }

                if (aux.Derecha == null)
                {
                    aux.Derecha     = nuevo;
                    nuevo.Izquierda = aux;
                }
            }
        }

        //INSERTANDO EN COLUMNAS
        Encabezado c = m.Columnas.getEncabezado(columna);

        if (c == null)
        {
            m.Columnas.Insertar(columna);
            c        = m.Columnas.getEncabezado(columna);
            c.Acceso = nuevo;
        }
        else
        {
            if (nuevo.Fila < c.Acceso.Fila)
            {
                c.Acceso.Arriba = nuevo;
                nuevo.Abajo     = c.Acceso;
                c.Acceso        = nuevo;
            }
            else
            {
                NodoMatriz aux = c.Acceso;
                while (aux.Abajo != null)
                {
                    if (nuevo.Fila < aux.Abajo.Fila)
                    {
                        nuevo.Abajo      = aux.Abajo;
                        nuevo.Arriba     = aux;
                        aux.Abajo.Arriba = nuevo;
                        aux.Abajo        = nuevo;
                        break;
                    }
                    aux = aux.Abajo;
                }

                if (aux.Abajo == null)
                {
                    aux.Abajo    = nuevo;
                    nuevo.Arriba = aux;
                }
            }
        }

        Matriz     ma;
        NodoMatriz nodo;

        //DEFINIENDO ARRIBA
        ma = m.Siguiente;
        while (ma != null)
        {
            nodo = ma.getNodo(fila, columna);
            if (nodo != null)
            {
                nuevo.Arriba = nodo;
                nodo.Abajo   = nuevo;
                break;
            }
            ma = ma.Siguiente;
        }

        //DEFINIENDO ABAJO
        ma = m.Anterior;
        while (ma != null)
        {
            nodo = ma.getNodo(fila, columna);
            if (nodo != null)
            {
                nuevo.Abajo = nodo;
                nodo.Arriba = nuevo;
                break;
            }
            ma = ma.Anterior;
        }
    }
Exemplo n.º 5
0
    public void Eliminar(String nombre)
    {
        NodoMatriz nodo = this.getNodo(nombre);

        if (nodo != null)
        {
            //ELIMINANDO EN FILAS
            Encabezado fila = this.Filas.getEncabezado(nodo.Fila);
            if (fila.Acceso == nodo)
            {
                fila.Acceso = nodo.Derecha;
                if (fila.Acceso == null)
                {
                    this.Filas.Eliminar(fila.Id);
                }
                else
                {
                    fila.Acceso.Izquierda = null;
                }
            }
            else
            {
                nodo.Izquierda.Derecha = nodo.Derecha;
                if (nodo.Derecha != null)
                {
                    nodo.Derecha.Izquierda = nodo.Izquierda;
                }
            }

            //ELIMINANDO EN COLUMNAS
            Encabezado columna = this.Columnas.getEncabezado(nodo.Columna);
            if (columna.Acceso == nodo)
            {
                columna.Acceso = nodo.Abajo;
                if (columna.Acceso == null)
                {
                    this.Columnas.Eliminar(columna.Id);
                }
                else
                {
                    columna.Acceso.Arriba = null;
                }
            }
            else
            {
                nodo.Arriba.Abajo = nodo.Abajo;
                if (nodo.Abajo != null)
                {
                    nodo.Abajo.Arriba = nodo.Arriba;
                }
            }

            //ELIMINANDO ARRIBA Y ABAJO
            if (nodo.Abajo != null)
            {
                nodo.Abajo.Arriba = nodo.Arriba;
            }
            if (nodo.Arriba != null)
            {
                nodo.Arriba.Abajo = nodo.Abajo;
            }
        }
    }
Exemplo n.º 6
0
        private void productoCP(object sender, EventArgs e)
        {
            if (!usuario.getCola().isEmpty())
            {
                if (!usuario.getPila().isEmpty())
                {
                    if (usuario.getCola().peek().getMatriz().getSizeX() == usuario.getPila().peek().getMatriz().getSizeY())
                    {
                        Matriz m1         = usuario.getCola().dequeue().getMatriz();
                        Matriz m2         = usuario.getPila().pop().getMatriz();
                        Matriz resultante = new Matriz(m2.getSizeX(), m1.getSizeY());

                        NodoMatriz nodo1 = m1.getRaiz();
                        NodoMatriz nodo2 = m2.getRaiz();

                        for (int y = 0; y < m1.getSizeY(); y++)
                        {
                            for (int x = 0; x < m2.getSizeX(); x++)
                            {
                                resultante.setValorMatriz(x, y, getProducto(nodo1, nodo2));
                                nodo2 = nodo2.getDerecha();
                            }
                            nodo1 = nodo1.getAbajo();
                            nodo2 = m2.getRaiz();
                        }

                        String dot = resultante.generarImagenMatriz();
                        // Delete the file if it exists.
                        if (File.Exists(path + "\\Dot\\matriz.dot"))
                        {
                            File.Delete(path + "\\Dot\\matriz.dot");
                        }
                        try
                        {
                            if (File.Exists(path + "\\Png\\matriz.png"))
                            {
                                File.Delete(path + "\\Png\\matriz.png");
                            }
                        }
                        catch (Exception)
                        {
                            foreach (Process proceso in Process.GetProcesses())
                            {
                                if (proceso.ProcessName == "Fotos.exe")
                                {
                                    proceso.Kill();
                                }
                            }
                            File.Delete(path + "\\Png\\matriz.png");
                        }
                        // Create the file.
                        using (FileStream fs = File.Create(path + "\\Dot\\matriz.dot"))
                        {
                            Byte[] info = new UTF8Encoding(true).GetBytes(dot);
                            fs.Write(info, 0, info.Length);
                            fs.Close();
                        }

                        Process cmd = new Process();
                        cmd.StartInfo.FileName              = "cmd.exe";
                        cmd.StartInfo.CreateNoWindow        = true;
                        cmd.StartInfo.RedirectStandardInput = true;
                        cmd.StartInfo.UseShellExecute       = false;
                        cmd.Start();
                        cmd.StandardInput.WriteLine($"dot -Tpng {path}\\Dot\\matriz.dot -o {path}\\Png\\matriz.png");
                        cmd.StandardInput.Flush();
                        cmd.StandardInput.Close();
                        abrirImagen("matriz.png");
                    }
                    else
                    {
                        MessageBox.Show("No se puede realizar la operación, el #columnas debe ser igual al #filas");
                    }
                }
                else
                {
                    MessageBox.Show("No hay datos en la pila, ingrese valores");
                }
            }
            else
            {
                MessageBox.Show("No hay datos en la cola, ingrese valores");
            }
        }