#include<iostream>
#include<string>
#include"SeqList.H"
#include"UFSet.H"
#include"MinHeap.H"
using namespace std;
const int MaxNumEdge=50;
const int MaxNumVertices=10;
class MinSpanTree;
template <class NameType,class DistType> class Graph
{
public:
Graph(int sz);
void Kruscal(MinSpanTree &T);
// private:
SeqList<NameType> VerticesList;
DistType Edge[MaxNumVertices][MaxNumVertices];
int CurrrentEdge;
};
const float MAXNUM=12345;
//
class MSEdgeNode
{
friend class MinSpanTree;
//private:
public:
int tail,head;
float cost;
};
//
class MinSpanTree
{
public:
MinSpanTree(int sz=MaxNumEdge-1):MaxSize(sz),n(0)
{edgevalue=new MSEdgeNode[MaxSize];}
int Insert(MSEdgeNode &item);
protected:
MSEdgeNode *edgevalue;
int MaxSize ,n;
};
//
template <class NameType,class DistType>
void Graph <NameType, DistType> ::Kruscal(MinSpanTree &T)
{
MSEdgeNode e;
MinHeap<MSEdgeNode> H(CurrrentEdge);
int NumVertices=VerticesList.MaxSize,u,v;
cout<<NumVertices;
/* UFSets F(NumVertices); F.Print();
for(u=0;u<NumVertices;u++)
for(v=u+1;v<NumVertices;v++)
if(Edge[u][v]!=MAXNUM){
e.tail=u;e.head;e.cost=Edge[u][v];H.Insert(e);
}
int count=1;
while(count<NumVertices)
{
H.RemoveMin(e);
u=F.Find(e.tail);v=F.Find(e.head);
if(u!=v){
F.Union(u,v);//T.Insert;
count++;
}
}
*/
}
//
template <class NameType,class DistType>
Graph <NameType, DistType> ::Graph(int sz)
{ CurrrentEdge=0;int Vertices;
cout<<"输入结点个数"<<endl;
cin>>Vertices;
SeqList<NameType> VerticesList(Vertices);
cout<<VerticesList.MaxSize;
cout<<"输入结点"<<endl;
for (int a=0;a<Vertices;a++)
{ NameType x;
cin>>x;
VerticesList.Insert(x);
}
cout<<"输入边数"<<endl;
cin>>sz;
cout<<"输入边:"<<endl;
for (int i=0;i<sz;i++)
{
cout<<"**"<<endl;
for(int j=0;j<sz;j++)
{
cin>>Edge[i][j];
if( Edge[i][j]!=0) CurrrentEdge++;
}
}
}
main()
{ MinSpanTree T;
Graph<string,float> a(9);
a.Kruscal(T);
}
Kruskal_suanfa.rar_Kruskal算法
版权申诉
89 浏览量
2022-09-24
12:46:20
上传
评论
收藏 2KB RAR 举报
林当时
- 粉丝: 95
- 资源: 1万+
最新资源
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈