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.
精彩评论