2
Who can help me and explain this problem I will be grateful
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BuscaLargura
{
partial class Program
{
static void Main(string[] args)
{
/* Node grafos = Grafo();
Console.WriteLine(" ");
bfs_transversal(grafos);*/
List<Node> listanos = new List<Node>();
List<Node> conectados = new List<Node>();
String[] text = System.IO.File.ReadAllLines(@"C:\Users\Pedro Pacheco\Desktop\Mapa.txt");
for (int i = 0; i < text.Length; i++)
{
if (text[i].Contains("city"))
{
//Console.WriteLine(text[i][5]);
listanos.Add(new Node(text[i][5]));//adiciona um Nó com o nome da 5 posição da linha do Mapa.txt
}
}
for (int i = 0; i < text.Length; i++)
{
if (text[i].Contains("route"))
{
Console.WriteLine(text[i][6]);
for (int nopai = 0; nopai < listanos.Count; nopai++)//varrendo os nós sem conexão
{
if (listanos[nopai].data == text[i][6])//verificando se o Nó.data é igual a text[i][6] ( exemplo= route=A)
{
for (int nofilho = 0; nofilho < listanos.Count; nofilho++)
{
if (listanos[nofilho].data == text[i][8])
{
Console.WriteLine(text[i][8]);
//listanos[nopai].conectados.Add(new Node(listanos[nofilho]));
conectados.Add(listanos[nofilho]);
}
}
listanos[nopai].conectados.AddRange(conectados);
conectados.Clear();
}
}
}
}
}
}
}
Node class:
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
using System.Threading.Tasks;
namespace BuscaLargura {
public class Node {
public List<Node> conectados;
public char data;
public Node(char data,List<Node> conectados)
{
this.conectados = conectados;
this.data = data;
}
public Node(char data)
{
this.data = data;
}
public Node (List<Node> filhos)
{
this.conectados.AddRange(filhos);
}
}
}
Without the definition of class
Node
makes it difficult to help you. If you decide to publish the Ode class, mark my name (with arroba) so that I can be notified. Hence I give you a force.– Augusto Vasques
@Augustovasques Pronto
– Pedro Pacheco
My intention is after I create these listings, for each of this list to assign to another list of connected
– Pedro Pacheco
connected public list; you sent it down there:
public List conectados;
would not bepublic List<Node> conectados;
?– Augusto Vasques
It was wrong because it did not find
Mapa.txt
????– Augusto Vasques
Map is reading perfectly
– Pedro Pacheco
Mine here, it’s not working because I don’t have that file. I need it
– Augusto Vasques
where I can make this map available ?
– Pedro Pacheco
Edit the post and pass either a link from it on an online file system (github type) or if it is short put in the edit itself.
– Augusto Vasques
Or just pass a fragment of it that works and generates the same error that is giving there with you.
– Augusto Vasques
I posted the Map @Augustovasques but this divided by lines
– Pedro Pacheco
Agr I have a doubt to separate the string -> route=A-C;140; and take only the 140
– Pedro Pacheco
String[] String.Split(char c)
– Augusto Vasques