博前感想:
图的遍历创建的思想比较容易懂,深度遍历和广度遍历需要自己动动脑筋。深度遍历是基于栈的思想--先进后出,广度遍历是基于队列的思想--先进先出。
代码块:
#include<string>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
//#include"x64/Debug/图的遍历.tlog/" 不行
using namespace std;
bool DFSvisit[26]; //两个存放有没有访问过的布尔型数组
bool BFSvisit[26];
typedef struct arcNode //边结构体
{
struct vNode;
int xiabiao; //下标
int weight; //每条弧的权重
arcNode *next; //连接下一个结构体的指针
vNode *visit; //访问顶点的指针
}arcNode;
typedef struct vNode //顶点结构体
{
arcNode *first;
string data;
int linenum;
//vNode hwq[13];
}adjlist;
typedef struct graph //图
{
adjlist hwq[13];
int vexnum, arcnum; //总的顶点数和边数
}graphadjlist;
void create(graphadjlist &h, adjlist &w) //创建图,加&的都是变量通用的
{
arcNode *temp; //边结构体的指针
arcNode *q; //也是同上
cout<<"请输入顶点数:"<<endl;
cin>>h.vexnum ; h.arcnum = 0; //初始化图的顶点数和边的数目
int x = 0;