Please help with a Java method for representing a directed graph using an adjacency matrix.
请帮助使用Java方法使用邻接矩阵表示有向图。
This is how the question was structured though: 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.
这就是问题的结构:写一个有向图方法写,它会写出指向终端的图形的相关信息。该图将使用邻接表/矩阵来实现。
1 个解决方案
#1
0
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.
首先,您要实现邻接矩阵。如果您不知道如何表示该数据结构,请阅读您的教科书或*。您将需要一个二维数组或一个数组数组。如果您需要更灵活的东西,请使用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.
编写一个diagraph方法write,它将向终端写入指定图形的相关信息。
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.
我无法确切地说出你的意思,但我认为它意味着:连接到A:{B,C,D}或定向路径:A-> B,B-> A,B-> C.您将需要将节点名称映射到邻接矩阵索引。一旦你有了这个,你可以通过迭代邻接矩阵并找到非零值来构建输出字符串。
#1
0
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.
首先,您要实现邻接矩阵。如果您不知道如何表示该数据结构,请阅读您的教科书或*。您将需要一个二维数组或一个数组数组。如果您需要更灵活的东西,请使用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.
编写一个diagraph方法write,它将向终端写入指定图形的相关信息。
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.
我无法确切地说出你的意思,但我认为它意味着:连接到A:{B,C,D}或定向路径:A-> B,B-> A,B-> C.您将需要将节点名称映射到邻接矩阵索引。一旦你有了这个,你可以通过迭代邻接矩阵并找到非零值来构建输出字符串。