Beispiel #1
0
        public static void Write()
        {
            Stack <Node> s    = new Stack <Node>();
            Node         from = graph.Find(entrada);
            Node         to   = graph.Find(saida);
            Node         aux  = to;

            while (aux != from)
            {
                s.Push(aux);
                aux = aux.Parent;
            }

            s.Push(aux);

            do
            {
                aux = s.Pop();
                if (aux.Name != entrada)
                {
                    Console.Write(aux.Parent.Name + " --> " + aux.Name);
                }
                Console.WriteLine("\n");
            } while (s.Count > 0);
            Console.ReadLine();
        }
Beispiel #2
0
        public static void WebCrawler(string html)
        {
            int    indice = -1;
            string aux;
            Node   from = queue.Dequeue(), to;

            do
            {
                aux    = "";
                indice = html.IndexOf("href=\"/wiki/", indice + 1);

                if (indice >= 0)
                {
                    int i = 12;
                    while (html[indice + i] != '\"')
                    {
                        aux += html[indice + i];
                        i++;
                    }

                    if (!urls.Contains(aux))
                    {
                        Node n = new Node();
                        n.Name = aux;
                        graph.AddNode(n.Name);
                        to = graph.nodes[graph.nodes.Count - 1];
                        graph.AddEdge(from.Name, to.Name);
                        queue.Enqueue(to);
                        to.Parent = from;
                        urls.Add(aux);
                    }
                    if (aux == saida)
                    {
                        Write();
                    }
                }
            } while (indice >= 0);

            GetRequest(common + queue.First());
        }