## finallyprim.m ( File view )

• By mulangic 2016-05-09
• View(s)：0
• Point(s)： 1
```			clear all;
close all;
Graph1;%调用Graph1M文件，产生图1的邻接矩阵
%Graph2;%调用Graph2M文件，产生图2的邻接矩阵

k=sprintf('please input the point where you want to start ,do remember it must be between 1 and %d ',len);
start_point=input(k);%输入最小生成树产生起点
while((start_point<=0)|(start_point>len))%如果输入的结点位置不合法即：小于等于零，或大于结点数，则重新输入
start_point=input(k);
end;
%************************************下面完成prim算法****************************
%相关变量初始设置
tree=zeros(len-1,2);%用于保存选入最小生成树的边
lowcost=zeros(1,len);%用来保存集合V-U与集合U中顶点的最短边权值，lowcost[v]=0表示顶点v已经
%加入最小生成树中
%首先U={
start_point
},之后依次确定为把最小生成树的一边的另一节点加入U
%依次下去，直到图的全部顶点都在U中能找到

%以下循n-1次，用于找出最小生成树的len-1条边

for i=1:len-1
k=lowcost>0;%k为一逻辑数组，它和lowcost同维，对于每一个位置i1lowcost(i)>0则k(i)=1
%否则k(i)=0;稍候将用这个数组进行辅助寻址
cost_min=min(lowcost(k));%找出lowcost中除0外的最小值
index=find(lowcost==cost_min);%找出此最小值在lowcost中的下标，即找到相应的节点
index=index(1);%因为最
...
...
```
...
Expand＞ ＜Close

Point(s): 1

0 lines left, continue to read

## File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
finallykruskal.m1.98 kB14-06-08|10:51
finallyprim.m2.35 kB14-06-08|10:51
Graph1.m321.00 B09-06-08|15:26
Graph11.m333.00 B09-06-08|21:11
Graph2.m392.00 B09-06-08|16:17
Graph22.m408.00 B09-06-08|21:12
kruskalenhance.m2.12 kB14-06-08|13:08
test.m153.00 B14-06-08|10:21
testsparse.m187.00 B14-06-08|10:44

code0.00 B17-11-08|22:23
prim0.00 B0|0%
...
• Sent successfully!
• MST prim and kruskal.rar
• 1 point

### finallyprim.m (330.27 kB)

Need 1 point

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

Don't have an account？ Register now
Need any help?
Mail to: support@codeforge.com

### 切换到中文版？

CodeForge Chinese Version
CodeForge English Version

### ^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!

### Warm tip!

Favorite by Ctrl+D