我尝试使用贪婪树算法提出最短路径算法 示例:Dijkstra或Prim 然而,我似乎无法弄清楚我应该如何制作我的数据结构。
当我尝试创建一个数据结构时,我所能做的就是以A到F的单向解决方案结束..但是你将无法从F转到A ..
现在我想知道,有人可以给我一个示例代码(Java首选)如何设置这样的结构?
我的最新尝试:
public class Point {
//public List<Point> connections = new ArrayList<Point>();
public List<Connection> connections = new ArrayList<Connection>();
public List<Point> connectedWith = new ArrayList<Point>();
public char name;
public Point(char name) {
this.name = name;
}
/*public Point getConnectionByIndex(int index) {
return this.connections.get(index);
}*/
}
和
public class Connection {
private Point nameFirst, nameSecond;
private int connectionLength;
public Connection(Point nameFirst, Point nameSecond, int connectionLength) {
this.setNameFirst(nameFirst);
this.setNameSecond(nameSecond);
this.connectionLength = connectionLength;
}
public int getConnectionLength() {
return connectionLength;
}
public void setConnectionLength(int connectionLength) {
this.connectionLength = connectionLength;
}
public Point getNameSecond() {
return nameSecond;
}
public void setNameSecond(Point nameSecond) {
this.nameSecond = nameSecond;
}
public Point getNameFirst() {
return nameFirst;
}
public void setNameFirst(Point nameFirst) {
this.nameFirst = nameFirst;
}
}
亲切的问候,
Larssy1
http://en.wikipedia.org/wiki/Dijkstra&#39; s_algorithm