我正在开展一个项目,我必须找到12个城市之间的最短路径,从西雅图开始,到迈阿密结束.我正在使用Dijkstra的算法,因为路径是加权的.到目前为止,这是我的代码,除了我得到的答案不是我需要的答案之外,它都有效,尽管它是正确的.
这部分代码设置了所有内容以及创建排序算法.
class Graph
{
Dictionary<string, Dictionary<string, int>> vertices = new Dictionary<string, Dictionary<string, int>>();
public void add_vertex(string name, Dictionary<string, int> edges)
{
vertices[name] = edges;
}
public List<string> shortest_path(string start, string finish)
{
var previous = new Dictionary<string, string>();
var distances = new Dictionary<string, int>();
var nodes = new List<string>();
List<string> path = null;
foreach (var vertex in vertices)
{
if (vertex.Key == start)
{
distances[vertex.Key] = 1;
}
else
{
distances[vertex.Key] = int.MaxValue;
}
nodes.Add(vertex.Key);
}
while (nodes.Count != …Run Code Online (Sandbox Code Playgroud) 我想知道如何在我设置的消息框中显示图像,这样每当鼠标输入标签时,它就会显示消息框.代码插入图像的代码是什么?