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

📄 kruskal.cpp

📁 data structures, algorithms and Application书的源代码
💻 CPP
字号:
// test Kruskal's min cost spanning tree algorithm

#include <iostream.h>
#include "lwg.h"

void main(void)
{
   LinkedWGraph<int> G(7);
   EdgeNode<int> t[7];
   int n = 7;
   int e, u, v, w;
   cout << "enter number of edges of 7 vertex graph" << endl;
   cin >> e;
   // get edges
   for (int i = 1; i <= e; i++) {
      cout << "enter edge " << i << endl;
      cin >> u >> v >> w;
      G.Add(u,v,w);}

   cout << "The input graph is" << endl;
   G.Output();

   if (G.Kruskal(t)) {
      cout << "The min spanning tree edges are" << endl;
      for (int i=0; i<n-1; i++)
         cout << t[i] << endl;}
   else  cout << "The graph is not connected" << endl;
}

⌨️ 快捷键说明

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