I am to read in a road map of interconnected cities and their corresponding distances as part of an assignment. The file has format like 'source city, destination city, distance between the two cities.' However, my code below does reads all of the source cities, but does not properly add all neighboring cities (i.e. not all city pairs are read in). Hope this makes sense and any help is much appreciated!
Thank you for your response gunnerfunner. Take for example the source file is:
New York, Boston, 190
Boston, Chicago, 50
Chicago, Milwaukee, 83
I am trying to get my code to show that neighbors of, say Boston, are New York and Chicago, instead of just Chicago. This is the specific part I am having trouble with, sorry if I wasn't overly specific earlier.
@Peanut373
You need to structure your data in a different way.
Create a 'connectivity array' as you read in the data. The array comprises rows and columns corresponding to the cities with the intersection of a row and column being the distance between the two cities.
Keep in mind the array is symmetrical.
Neighbours are simply cities with a non-zero entry in the array for a particular row (or column).