⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prim.m

📁 prim算法 kruskal算法用matlab实现 输入标准:x邻接矩阵 p节点集 输出:生成树边集 G
💻 M
字号:
function [u,l]=prim(x,p)
%u is the set of the point serial
%l is the set of the length of sides serial
%x is adjacing matrix
%p is the set of all the point 
u=[1];
l=[];

while length(p)~=0
    lmin=inf;
    %calculate the min length of side from u to p-u
    p=setdiff(p,u);
    lrem=0;
    urem=0;
    for ii=1:length(u)
        for jj=1:length(p)
         if lmin>x(u(ii),p(jj)) 
         lmin=x(u(ii),p(jj));
         lrem=lmin;
         urem=p(jj);
         end
        end
    end
    u=[u urem];
    l=[l lrem];
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -