7.4.1无向图的连通分量和生成树

2020-11-29 00:42

============================================================
e1:建立无向图的深度优先森林(DFSForest,G2).
// xx.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream.h"
#include "math.h"
#include "stdio.h"
#include "stdlib.h"
//#####################图的邻接表声明,和相关操作。
#define INFINITY INT_MAX
#define MAX_VERTEX_NUM 20
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
typedef int VRType;
typedef char VertexType;
typedef int Status;


typedef struct ArcNode
{
int adjvex; //该弧所指向的顶点的位置。
struct ArcNode *nextarc;
}ArcNode;

typedef struct VNode
{
VertexType data;
ArcNode *firstarc;
}VNode, AdjList[MAX_VERTEX_NUM];

typedef struct
{
AdjList vertices;
int vexnum, arcnum;
}ALGraph;

bool visited[MAX_VERTEX_NUM];
Status (*VisitFunc)(int v);
//int w;

void CreateGraph(ALGraph &G);
void DFSTraverse(ALGraph G, Status (*Visit)(int v));
Status printGraph(int v);
int FirstAdjVex(ALGraph G, int v);
int NextAdjVex(ALGraph G, int v, int w);
void DFS(ALGraph G, int v);
//#####################树的孩子兄弟链表声明,和相关操作。
//树的孩子兄弟链表。

typedef char TElemType;
typedef struct CSNode
{
TElemType data;
CSNode *firstchild,*nextsibling;
}CSNode,*CSTree;

typedef CSTree QElemType;
//typedef char TElemType;
TElemType Nil=' ';
void DFSForest(ALGraph G,CSTree &T);
void DFSTree(ALGraph G,int v,CSTree &T);
TElemType GetVex(ALGraph G,int v);
void LevelOrderTraverse(CSTree T,void(*Visit)(TElemType));
TElemType Value(CSTree p);
void vi(TElemType c);
//#####################队列的声明,和相关操作。
//队列的链式存储结构
typedef struct QNode
{
QElemType data;
QNode *next;
}*QueuePtr;

struct LinkQueue
{
QueuePtr front,rear;
};

Status DeQueue(LinkQueue &Q,QElemType &e);
Status InitQueue(LinkQueue &Q);
Status QueueEmpty(LinkQueue Q);
Status EnQueue(LinkQueue &Q,QElemType e);
//##################
void main( void )
{
printf("-------beg-----\n");
int i;
ALGraph G;
ArcNode *p;
CSTree cst;
CreateGraph(G);

for(i= 0; i < G.vexnum; i++)
{
printf("-%d#%c",i,G.vertices[i].data);
p = G.vertices[i].firstarc;
while(p != NULL)
{
printf("--->");
printf("%c",G.vertices[p->adjvex].data);
p = p->nextarc;
}
printf("\n");
}
printf("------------------------in_main_before_DFSTraverse--\n");
DFSTraverse(G, printGraph);
printf("------------------------in_main_before_DFSForest--\n");
DFSForest(G,cst);
printf("-----------------------------------------before_LevelOrderTraverse--\n");
//printf("--");
LevelOrderTraverse(cst,vi);
//printf("--\n");
printf("-------end-----\n
");
}//main
//建立无向图。
void CreateGraph(ALGraph &G)
{
int i, j = 0, k = 0;
char hand, tide;
ArcNode *p;
char vertices[]={'a','


7.4.1无向图的连通分量和生成树.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:加油站环保制度及相关防护措施

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: