用Java实现邻接矩阵
我的任务是创建一个类“GraphOfCity”,该类运行并解释下面包含的驱动程序代码中的方法 每次我在GraphOfCity上取得进展,我最终都会做错事,回到原点 我创建了一个类“Graph”作为占位符,而类GraphOfCity扩展了Graph。这是我所能做到的。我相信我需要使用邻接矩阵来执行所有操作 GraphOfCity需要包含的方法: getSize() GetNeights() getDegree() isEmpty() addVertex() addEdge() printededges() 打印顶点() deleteEdge() 我已经尝试了几个小时,但没有取得任何进展,提前感谢您 驱动程序代码:用Java实现邻接矩阵,java,arraylist,graph,adjacency-matrix,Java,Arraylist,Graph,Adjacency Matrix,我的任务是创建一个类“GraphOfCity”,该类运行并解释下面包含的驱动程序代码中的方法 每次我在GraphOfCity上取得进展,我最终都会做错事,回到原点 我创建了一个类“Graph”作为占位符,而类GraphOfCity扩展了Graph。这是我所能做到的。我相信我需要使用邻接矩阵来执行所有操作 GraphOfCity需要包含的方法: getSize() GetNeights() getDegree() isEmpty() addVertex() addEdge() printededg
public class testcode01 {
public static void main(String args[])
{
Graph graph01 = new GraphOfCity();
String[] city = {"Little Rock", "Fayetteville", "Bentonville", "Fort Smith", "Harrison"};
int[][] distance =
{
{0, 92, 106, 136, 67},
{92, 0, 80, 120, 152},
{106, 80, 0, 209, 175},
{136, 120, 209, 0, 95},
{67, 152, 175, 95, 0}
};
Graph graph02 = new GraphOfCity(city, distance);
graph01.getSize();
graph02.getSize();
graph01.getNeighbors("Fayetteville");
graph02.getNeighbors("Fayetteville");
graph01.getDegree("Fayetteville");
graph02.getDegree("Fayetteville");
graph01.isEmpty();
graph02.isEmpty();
graph01.addVertex("Little Rock");
graph01.addVertex("Fayetteville");
graph01.addVertex("Bentonville");
graph01.addEdge("Little Rock", "Fayetteville", 45);
graph01.addEdge("Little Rock", "Bentonville", 142);
graph01.addEdge("Fayetteville", "Bentonville", 73);
graph01.printEdges();
graph01.printVertices();
graph02.printEdges();
graph02.printVertices();
graph01.deleteEdge("Fayetteville", "Bentonville");
graph01.deleteEdge("Fayetteville", "Bentonville");
graph02.deleteEdge("Fayetteville", "Bentonville");
graph02.deleteEdge("Fayetteville", "Bentonville");
}
}如果没有你的
Graph
类的代码,我们就说不出多少。
你在哪里卡住了?这是所有给出的代码。我创建了另一个“Graph”类作为占位符,并使GraphOfCity扩展了Graph。在此之后,我尝试了一些不同的方法来让GraphOfCity类朝着正确的方向发展,但是我对邻接矩阵的实现以及如何实现所有请求的方法非常模糊。谢谢