发布时间 : 星期一 文章最小生成树MFC实现更新完毕开始阅读
#include \#include \#include \#include \#include \
//#define INFINITY INT_MAX #define MAX_VERTEX_NUM 20 #define OVERFLOW -1 typedef int VRType;
typedef char VertexType; typedef int GraphKind; typedef int InfoType;
typedef struct ArcCell{ int adj; //char *info;
}ArcCell, AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM]; typedef struct{ char vexs[MAX_VERTEX_NUM]; AdjMatrix arcs; int vexnum,arcnum; }MGraph;
struct {
char adjvex; VRType lowcost;
}closedge[MAX_VERTEX_NUM];
int GetVexNum(CString &A)
{//统计结点的个数 int i=0; while(i char* GetVexs(CString &A) {//返回结点数组 char* p=(char*)malloc(sizeof(char)); char Array[MAX_VERTEX_NUM]=\ p=Array; int i=0 , j=0; while(i if(A.GetAt(i)==13) break;//当是回车时 if(A.GetAt(i)=='0') {i++;continue;}//当是0时 Array[j] = A.GetAt(i); i++; j++; } else i++; } return p; } char** GetArcs(CString &A) {//获得的是含权的邻接矩阵 int m=0 , n=0, i=0,j=0, k=0; char **p; p=(char**)malloc(MAX_VERTEX_NUM*sizeof(char*)); for(i=0;i else {++m;n=0;i+=5;flag=0;} } for(int c=0;c int minimum() { int MinCost=100,MinNum=0; for( int j=0; j<5 ;j++) if(closedge[j].lowcost>0&& closedge[j].lowcost struct student//用来存储边 { char top; char base; }; struct student closed[MAX_VERTEX_NUM]; int flag=0; void MiniSpanTree_PRIM(MGraph G, VertexType u) { int i=0,j=0,k=0,n=0,m=0,g=0,h=0; k=0; for(j=0;j closed[flag].base= G.vexs[k]; flag++; closedge[k].lowcost=0; for(j=0;j int Check_Arcs(MGraph G) { for(int i=0;i int Check_Num(MGraph G,CString A) { if(((G.vexnum+1)*2+1)*G.vexnum-2==A.GetLength()) return 1; else return 0; } void CGraphgDlg::OnShow_Tree() { UpdateData(true); MGraph G; //char* p=(char*)malloc(sizeof(char)); char *p = GetVexs(m_Input); int i=0; for( i=0 ; i