数据结构与算法 ~ 图 ~ 最小生成树 ~ 克鲁斯卡尔算法(图采用邻接表方式存储)

数据结构与算法 ~ 图 ~ 最小生成树 ~ 克鲁斯卡尔算法(图采用邻接表方式存储)

/* graph ------adjacency List */
#include<stdlib.h>
#include<stdio.h>
#define  MAX  20
/*弧结点信息*/
struct ArcNode{
	int  adjvex;/*该弧所指向的顶点的信息*/
	int  cost;
	int  visited;
	struct ArcNode *nextarc; /*指向下一条弧的指针*/
};

struct VexNode{
	int data;/*顶点信息*/
	int muster;/*顶点所属集合*/
	struct ArcNode  *firstarc;/*指向第一条依附于该顶点的弧的指针*/
};
struct  VexNode  head[MAX];/*顶点数组*/
int  vexnum=-1;
int graphtype;

int formatlist(){
  printf("\n1---创建无向图:");
  printf("\n2---创建有向图:");
  printf("\n0---退出");
  printf("\n请输入选择:");
  scanf("%d",&graphtype);
  return graphtype;
}

void constr(struct VexNode *head,int source, int destination,int cost){
	int max;
	struct ArcNode  *newNode,*pointer;
	newNode=(struct ArcNode*)malloc(sizeof(struct ArcNode));/*分配空间*/
	if (newNode==NULL){
		printf("错误!");
		exit(0);
	}else{
       newNode->adjvex=destination;                        /*生成弧结点*/
       newNode->cost=cost;
       newNode->nextarc=NULL;
       newNode->visited=0;
       if ( head[source].firstarc==NULL)               /*头结点没有邻接点*/
                  head[source].firstarc=newNode;
      else{
		 
  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值