[C] 用Kruskal算法构造图的最小生成树 →→→→→进入此内容的聊天室

来自 , 2019-03-17, 写在 C, 查看 136 次.
URL http://www.code666.cn/view/9bb6dee7
  1. typedef int elemtype;
  2. typedef struct
  3. {
  4.         elemtype v1;
  5.         elemtype v2;
  6.         int cost;
  7. } EdgeType;
  8.  
  9.  
  10. void Kruskal(EdgeType edges[ ]int n)
  11. /*用Kruskal 方法构造有n 个顶点的图edges 的最小生成树*/
  12. { int father[MAXEDGE];
  13.   int i,j,vf1,vf2;
  14.   for ( i=0; i<n; i++ ) father[i]=-1;
  15.   i=0;
  16.   j=0;
  17.   while ( i<MAXEDGE && j<n-1 )
  18. {
  19.         vf1=Find ( father,edges[i].v1 );
  20.                 vf2=Find ( father,edges[i].v2 );
  21.                 if ( vf1!=vf2 )
  22.                 {
  23.                         father[vf2]=vf1;
  24.                         j++;
  25.                         printf (%3d%3d\n”,edges[i].v1,edges[i].v2 );
  26.                 }
  27.                 i++;
  28.         }
  29. }
  30.  

回复 "用Kruskal算法构造图的最小生成树"

这儿你可以回复上面这条便签

captcha