Hi all.

Could anybody tell me how can I load to the memory a weighted graph from a file?


Use a 2D array or a sparse matrix.

How do you plan to use the graph?

My intention is to describe the weighted graph in a text file and then load it automatically to the memory (using a list) to implement at the end dijkstra's algorithm.

Ah, a 1D list. OK.

If you are at liberty to create your own input file, I suggest you make it something easy to read (programmatically), like:

0 12 0 2
1 24 0 2
2 13 1

where the first number on the line is the node number, the second is its weight, and any remaining are edges leaving the node. (You don't actually have to list the node number, you could just deduce it from the line number as you read...)

Make yourself a record that represents a node. Then use an array of that record type. All you have to do then is read one line at a time into one node at a time.

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.