Esempio n. 1
0
        public Byte[] topGrafo(String top)
        {
            listaTop = new ListaTop();
            if (top.Equals("Eliminados"))
            {
                listaEliminados(arbol.Raiz);
            }
            else
            {
                listaContactos(arbol.Raiz);
            }

            dot = "digraph Top{\n";
            NodoTop aux = listaTop.Cabeza;
            int     i   = 0;

            while (aux != null && i < 10)
            {
                dot = dot + aux.Nickname + "[label=\"Nickname: " + aux.Nickname + "\\n Cantidad: " + aux.Cantidad.ToString() + "\"]\n";
                aux = aux.Siguiente;
                i++;
            }

            aux = listaTop.Cabeza;
            i   = 0;
            while (aux.Siguiente != null && i < 9)
            {
                dot = dot + aux.Nickname + "->" + aux.Siguiente.Nickname + ";\n";
                aux = aux.Siguiente;
                i++;
            }
            dot = dot + "}\n";

            TextWriter t = new StreamWriter(@"C:\GrafosEDD\grafoTop.dot");

            t.WriteLine(dot);
            t.Close();

            Byte[] a = new Byte[0];

            String comando       = "\"C:/Program Files (x86)/Graphviz2.38/bin/dot.exe\" -Tpng C:\\GrafosEDD\\grafoTop.dot -o C:\\GrafosEDD\\grafoTop.png";
            var    procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c" + comando);
            var    proc          = new System.Diagnostics.Process {
                StartInfo = procStartInfo
            };

            proc.Start();
            proc.WaitForExit();

            FileStream foto = new FileStream("C:\\GrafosEDD\\grafoTop.png", FileMode.OpenOrCreate, FileAccess.ReadWrite);

            a = new Byte[foto.Length];
            BinaryReader reader = new BinaryReader(foto);

            a = reader.ReadBytes(Convert.ToInt32(foto.Length));
            foto.Close();

            return(a);
        }
Esempio n. 2
0
        public void Insertar(String nickname, int cantidad)
        {
            NodoTop nuevo = new NodoTop(cantidad, nickname);

            if (Cabeza == null)
            {
                Cabeza = nuevo;
            }
            else
            {
                if (Cabeza.Cantidad < cantidad)
                {
                    nuevo.Siguiente = Cabeza;
                    Cabeza.Anterior = nuevo;
                    Cabeza          = nuevo;
                }
                else
                {
                    NodoTop aux = Cabeza;
                    while (aux.Siguiente != null)
                    {
                        if (aux.Siguiente.Cantidad <= cantidad)
                        {
                            aux.Siguiente.Anterior = nuevo;
                            nuevo.Siguiente        = aux.Siguiente;
                            aux.Siguiente          = nuevo;
                            nuevo.Anterior         = aux;
                            break;
                        }
                        aux = aux.Siguiente;
                    }
                    if (aux.Siguiente == null)
                    {
                        aux.Siguiente  = nuevo;
                        nuevo.Anterior = aux;
                    }
                }
            }
        }