开发者

Java method for representing diagraphs using adjacency matrix

开发者 https://www.devze.com 2023-02-25 04:26 出处:网络
Please help with a Java method for representing a directed graph using an adjacency matrix. This is how the question was structured tho开发者_高级运维ugh:

Please help with a Java method for representing a directed graph using an adjacency matrix.

This is how the question was structured tho开发者_高级运维ugh: Write a diagraph method write that will write pertinent information specifying a graph to the terminal. The graph is to be implemented with an adjacency table/matrix.


First, you want to implement the adjacency matrix. If you do not know how to represent that data structure, read your textbook or Wikipedia. You will want a 2-D array, or an array of arrays. If you need something more flexible, use an ArrayList.

Once you have that implemented, you need to

Write a diagraph method write that will write pertinent information specifying a graph to the terminal.

I cannot say for sure what you mean by this, but I assume it means something like: Connections to A: { B, C, D } or Directed Paths: A->B, B->A, B->C. You will need a mapping of the node names to the adjacency matrix indices. Once you have that you can build your output string by iterating through the adjacency matrix and finding the non-zero values.

0

精彩评论

暂无评论...
验证码 换一张
取 消