How to implement this algorithm, if I have a graph presented in the form of a list of edges. With the adjacency matrix, everything is clear, but with the list ... PS Or can someone tell me how to go from the list of edges to the adjacency matrix
Closed due to the fact that off-topic participants BogolyubskiyAlexey , Aries , ermak0ff , Vladimir Glinskikh , Visman Sep 18 '15 at 10:15 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - BogolyubskiyAlexey, Aries, ermak0ff, Vladimir Glinskikh, Visman
|
1 answer
Create an empty adjacency matrix and fill in the required values in the list of edges. An element from the list of edges is a pair of numbers, each of which represents a vertex number. So, to fill the adjacency matrix, you just need to run through all the edges from the list.
Suppose you have a edge (1,2). So the element of the matrix, standing in 1 row and in column 2 is equal to one. And so, running through the entire list, fill in the adjacency matrix.
- @ barselona1002, cite the structure of the element of the list of edges (or look at it yourself carefully). - avp
- @avp, that is, the third column of the list of edges - distance - barselona1002
- I do not know how your list of edges is stored, but let's say it is stored in txt. Each line - edge. Then you simply read line by line, parse the string and then: the first element is the row of the matrix, the second is the column, the third is the value. - Stas0n
- one@barselona, examine the pointers (links) and list data structures, I think it will be just right for the graph representation and the implementation of the Dijkstra algorithm. - avp
|