Dijkstra算法步骤
(1)构造邻接矩阵
(2)定义起始点
(3)运行代码
M=[ 0 5 9 Inf Inf Inf Inf
Inf 0 Inf Inf 12 Inf Inf
Inf 3 0 15 Inf 23 Inf
Inf 6 Inf 0 Inf 8 7
Inf 12 Inf 5 0 Inf 14
Inf Inf Inf Inf Inf 0 10
Inf Inf Inf Inf Inf Inf 0];
first=2;
last=4;
[m,n]=size(M);
L=zeros(1,m);
symbol=zeros(1,m);
direction=zeros(1,m);
for i=1:m
if(i~=first)
L(i)=inf;
end
direction(i)=first;
end
judge=1;
while judge
for i=1:m
if(symbol(i)==0)
min=L(i);
temporary=i;
break
end
end
for i=1:m
if(symbol(i)==0)
if(L(i)