图的遍历和生成树求解实现(限 1 人完成)
要求:
1)先任意创建一个图;
2)图的 DFS,BFS 的递归和非递归算法的实现
3)最小生成树(两个算法)的实现,求连通分量的实现
4)要求用邻接矩阵、邻接表、十字链表多种结构存储实现
#include <iostream>
#include <malloc.h>
using namespace std;
#dene int_max 10000
#dene inf 9999
#dene max 20
//…………………………………………邻接矩阵定义……………………
typedef struct ArcCell
{
int adj;
char *info;
}ArcCell,AdjMatrix[20][20];
typedef struct
{
char vexs[20];
AdjMatrix arcs;
int vexnum,arcnum;
}MGraph_L;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^
int localvex(MGraph_L G,char v)//返回 V 的位置
{
int i=0;
while(G.vexs[i]!=v)
{
++i;
}
return i;
}
int creatMGraph_L(MGraph_L &G)//创建图用邻接矩阵表示
{
char v1,v2;
int i,j,w;
cout<<"…………创建无向图…………"<<endl<<"请输入图 G 顶点和弧的
个数:(4 6)不包括“()”"<<endl;
cin>>G.vexnum>>G.arcnum;