使用邻接矩阵表示图的Java方法
请帮助使用 Java 方法来使用邻接矩阵表示有向图。
这就是问题的结构: 编写一个图方法write,它将指定图形的相关信息写入终端。该图将通过邻接表/矩阵来实现。
Please help with a Java method for representing a directed graph using an adjacency matrix.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您要实现邻接矩阵。如果您不知道如何表示该数据结构,请阅读教科书或维基百科。您将需要一个二维数组或数组的数组。如果您需要更灵活的东西,请使用 ArrayList。
实施后,您需要
我不能确定你的意思,但我认为它的意思是这样的:
到A的连接:{B,C,D}或有向路径:A->B,B->A,B->C。您将需要节点名称到邻接矩阵索引的映射。一旦完成,您就可以通过迭代邻接矩阵并查找非零值来构建输出字符串。
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
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.