C语言数据结构克鲁斯卡尔算法-求最小生成树

/*
*克鲁斯卡尔算法
*得到图的最小生成树
*构造一个无向网的的邻接矩阵
*创建一个临时数组
*对edge数组进行排序
*/

#include
#include
#include
typedef char* VertexType;//顶点的信息的数据类型
typedef int ArcType;//权重胡数据类型
#define VERTEXNUM 100//最大顶点数
#define MAX_INT 32726 //权重的无限大取值
#define OK 1
#define ERROR 0
typedef struct edge
{
   ArcType weight;//边的权重
   VertexType head;//一条边的第一的节点
   VertexType tail;//一条边的第二个节点

}Edge[VERTEXNUM],edg;//创建边的数组
Edge edge;

typedef struct
{
	VertexType vexs[VERTEXNUM];//无向网的顶点数组
	ArcType arc[VERTEXNUM][VERTEXNUM];//边权重的二维数组
    int n,e;//网的边数和顶点数

}ALGraph;//无向网的结构体
void test();//测试函数
int create_algraph(ALGraph *G);//创建无向网
int locate_vex(ALGraph *G,VertexType vex);//定位函数
void  sort_array(ALGraph *G);//对权重进行排序
//克鲁斯卡尔算法
void main()
{
   test();
}
int create_algraph(ALGraph *G)//创建无向网
{
	int i;
	int j;
	//Edge edge;
	int now_weight;//当前权重
	 VertexType vex1;
	 VertexType vex2;
	 int x,y;
	printf("请输入网的顶点数ÿ

你可能感兴趣的:(数据结构与算法(c语言),c语言,C语言数据结构)