Ai
2 Star 0 Fork 0

CS-IMIS-23/GK20172301_JavaProgramming

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AirTraffic.java 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
package week9;
import java.util.Iterator;
public class AirTraffic<T> extends NetWork<T>{
public AirTraffic()
{
super();
}
public void addCity(T city)
{
addVertex(city);
}
public void addEdge(T city1,T city2,double weight)
{
addEdge(getIndex(city1),getIndex(city2),weight);
}
public void getShortestPath(T city1,T city2)
{
int index1 = getIndex(city1);
int index2 = getIndex(city2);
if (shortestPathLength(index1,index2)==0)
System.out.println("无法连通城市:"+city1+" "+city2);
else {
System.out.println("最短路径长度为:"+shortestPathLength(index1,index2));
String result = "";
Iterator iterator = iteratorShortestPath(index1,index2);
while (iterator.hasNext())
result += iterator.next()+" ";
System.out.println("最短路径为:"+result);
}
}
public void getShortestWeightPath(T city1,T city2) {
if (shortestPathLength(city1, city2) < Double.POSITIVE_INFINITY)
System.out.println("最便宜的价格为:" + shortestPathWeight(city1, city2));
else
System.out.println("无法连通城市:" + city1 + " " + city2);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/GK20172301_JavaProgramming.git
git@gitee.com:CS-IMIS-23/GK20172301_JavaProgramming.git
CS-IMIS-23
GK20172301_JavaProgramming
GK20172301_JavaProgramming
master

搜索帮助