使用队列以及深度搜索算法,加上dos命令调用图片的校园导游系统
#define _CRT_SECURE_NO_WARNINGS
# include<stdio.h>
# include<stdlib.h>
# include<string.h>
# include<Windows.h>
struct graph {
int node_num; //顶点数
int edge_num; //边数
char node_name[20][50]; //顶点数据,使用二维字符数组存储地点名称
int records[20]; //用于深搜标记走过的节点,0代表未走过,-1代表已走过
int weight[20][20]; //邻接矩阵,显示权值
};
struct my_queue { //用于深搜记录路径的队列
int data[500];
int front, rear; //队首,队尾元素
};
void init_graph(struct graph*& p, int n_num) //初始化图
{
p = (graph*)malloc(sizeof(graph));
if (p == NULL)
{
return;
}
p->node_num = n_num;
p->edge_num = 0; //初始化边数为0
for (int i = 0; i < p->node_num; i++)
{
p->records[i] = 0; //初始化节点的标记
for (int j = 0; j < p->node_num; j++)
{
p->weight[i][j] = 0; //初始化每条边的权重为0
}
}
}
void print_graph(struct graph* p)//打印图的邻接矩阵
{
for (int i = 0; i < p->node_num; i++)
{
for (int j = 0; j < p->node_num; j++)
{
printf("%d ", p->weight[i][j]); //打印出图
if (j == p->node_num - 1) printf("\n");
}
}
}
void name_strcpy(struct graph*& p, char a[][50], int n_num) //给图结构体里的节点赋值数据
{
int i = 0;
for (i; i < n_num; i++)
{
strcpy_s(p->node_name[i], a[i]);
//printf("%s\n", p->node_name[i]);
}
}
void quan_juzhen(struct graph*& p) //输入地图权重数据到邻接矩阵
{
p->weight[0][1] = 50;
p->weight[0][6] = 50;
p->weight[1][0] = 50;
p->weight[1][2] = 70;
p->weight[1][4] = 20;
p->weight[2][1] = 70;
p->weight[2][3] = 120;
p->weight[3][2] = 120;
p->weight[3][4] = 100;
p->weight[3][5] = 100;
p->weight[4][1] = 20;
p->weight[4][3] = 100;
p->weight[4][5] = 110;
p->weight[4][7] = 20;
p->weight[5][3] = 100;
p->weight[5][4] = 110;
p->weight[6][0] = 50;
p->weight[6][8] = 100;
p->weight[7][4] = 20;
p->weight[7][9] = 10;
p->weight[7][10] = 30;
p->weight[8][6] = 100;
p->weight[8][12] = 20;
p->weight[8][13] = 25;
p->weight[8][9] = 10;
p->weight[9][7] = 10;
p->weight[9][8] = 10;
p->weight[9][13] = 20;
p->weight[10][7] = 30;
p->weight[10][11] = 10;
p->weight[11][10] = 10;
p->weight[11][14] = 30;
p->weight[11][16] = 40;
p->weight[11][15] = 20;
p->weight[12][8] = 20;
p->weight[12][13] = 10;
p->weight[13][8] = 25;
p->weight[13][9] = 20;
p->weight[13][12] = 10;
p->weight[13][14] = 15;
p->weight[14][13] =
标签:node,10,20,weight,int,导游,C语言,num,数据结构
From: https://blog.csdn.net/luoyinan_CSDN/article/details/143804814