C++最小生成树的程序
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 09:37:29
C++最小生成树的程序
C++最小生成树的程序
C++最小生成树的程序
#include
#include
#include
#define MAX 100
typedef struct dege
{
int vex1;
int vex2;
int weight;
}Edge;
typedef struct linknode
{
int vex;
int weight;
struct linknode * next;
}LINKNODE;
typedef struct node
{
int data;
struct linknode * first;
}NODE;
typedef struct cd
{
int adjvex;
int lowcost;
}CD;
NODE G[MAX];
Edge E[MAX];
CD closedge[MAX];
int GRAPH[MAX][MAX];
int visited[MAX];
int graphcount;
void printgraph();
void convert();
void prim(int u);
int main()
{
int i;
int tempcount,temp;
LINKNODE *p;
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&tempcount);
while(tempcount!=0)
{
graphcount=tempcount;
for(i=0;iweight=temp;
p->next=G[i].first;
G[i].first=p;
scanf("%d",&temp);
}
}
scanf("%d",&tempcount);
}
printgraph();
convert();
prim(0);
return 0;
}
void printgraph()
{
int i;
LINKNODE *p;
for(i=0;ivex,p->weight);
p=p->next;
}
printf("\n");
}
}
void prim(int u)
{
int i,j,min,p;
for(j=0;j