使用地图,我需要找到两个车站之间的路径。例如,如果用户说他/她在劳伦斯,并且想去埃格林顿,则输出应该是 。"Lawrence, 100, 30, Kennedy, 19, Eglinton"使用可用的代码(如Dijkstra算法或A *搜索算法)没有问题(这可能是我需要的最佳代码,不确定)。但我确实需要使用某种类型的数组,队列或列表。地图的这种实现是否有效?还是我必须创建一个矩阵?String ThreeArray[][] = new String [2][7];ThreeArray[0][0] = "140";ThreeArray[0][1] = "134";ThreeArray[0][2] = "Lawrence";ThreeArray[0][3] = "100";ThreeArray[0][4] = "30";ThreeArray[0][5] = "Summerhill";ThreeArray[0][6] = "Warden";ThreeArray[0][7] = "Broadview";ThreeArray[1][0] = "Chester";ThreeArray[1][1] = "Kennedy";ThreeArray[1][2] = "19";ThreeArray[1][3] = "Eglinton";ThreeArray[2][0] = "Donalds";ThreeArray[2][1] = "Davisville";ThreeArray[2][2] = "Yorkdale";ThreeArray[2][3] = "Midland";
2 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
这可能会派上用场:https://www.baeldung.com/java-graphs。您可以将数据表示为图形,然后应用您认为合适的公式来计算距离。
添加回答
举报
0/150
提交
取消