⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 校园导航.cpp

📁 这是我数据结构课程设计的原代码,已经经过调试通过了的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#define INFINITY 10000 /*无穷大*/
#define MAX_VERTEX_NUM 60
#define MAX 60
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
typedef struct ArCell
{
int adj; //路径长度
}ArCell,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
typedef struct //图中顶点表示主要景点,存放景点的编号、名称、简介等信息,
{
char name[30];
int num;
char introduction[100];//简介
}infotype;
typedef struct
{
infotype vexs[MAX_VERTEX_NUM];
AdjMatrix arcs;
int vexnum,arcnum;
}MGraph;
MGraph b;
char a[13][14][11];
void cmd(void);
MGraph InitGraph(void);
void Menu(void);
void Browser(MGraph *G);
void ShortestPath_DIJ(MGraph * G);
void Floyd(MGraph *G);
void Search(MGraph *G);
int LocateVex(MGraph *G,char* v);
MGraph * CreatUDN(MGraph *G);
void printgood();
void print(MGraph *G);
/******************************************************/
void main(void)
{
system("color 1f");
system("mode con: cols=140 lines=130");
cmd();
}
/******************************************************/

void cmd(void)
{
int i;
b=InitGraph();
Menu();
scanf("%d",&i);
while(i!=5)
{
switch(i)
{
case 1:system("cls");Browser(&b);Menu();break;
case 2:system("cls");ShortestPath_DIJ(&b);Menu();break;
case 3:system("cls");Floyd(&b);Menu();break;
case 4:system("cls");Search(&b);Menu();break;
case 5:exit(1);break;
default:break;
}

scanf("%d",&i);
}
}
MGraph InitGraph(void)
{
MGraph G;
int i,j;
G.vexnum=14;
G.arcnum=20;
for(i=0;i<G.vexnum;i++)
G.vexs[i].num=i;
strcpy(G.vexs[0].name,"图书馆");
strcpy(G.vexs[0].introduction,"各类书籍齐全,且按大类分楼层收藏,方便学生查找");
strcpy(G.vexs[1].name,"本部教学楼");
strcpy(G.vexs[1].introduction,"分4大楼(南楼北楼,升华前楼升华后楼),供基础教学用");
strcpy(G.vexs[2].name,"饮食文化城");
strcpy(G.vexs[2].introduction,"二楼左边为5食堂,一楼和二楼右边为5食堂,是学生的主要用餐场所");
strcpy(G.vexs[3].name,"本部职工医院");
strcpy(G.vexs[3].introduction,"分住院部和门诊大楼,设施较为齐全,环境很好,只是收费较贵");
strcpy(G.vexs[4].name,"云麓山庄");
strcpy(G.vexs[4].introduction,"背靠巍巍的岳麓山,环境舒适,设施一流,供学校贵宾入住");
strcpy(G.vexs[5].name,"本部体育场");
strcpy(G.vexs[5].introduction,"现代化塑胶跑道,人造草坪,供体育教学用,也可供学生平常进行体育锻炼");
strcpy(G.vexs[6].name,"后街");
strcpy(G.vexs[6].introduction,"各种小吃,水果,生活用品,小饰品应有尽有");
strcpy(G.vexs[7].name,"本部商业街");
strcpy(G.vexs[7].introduction,"有较多书店,文具店,打印社和服装服饰店");
strcpy(G.vexs[8].name,"米塔尔大楼");
strcpy(G.vexs[8].introduction,"由米塔尔公司建造,供办公用");
strcpy(G.vexs[9].name,"西大门");
strcpy(G.vexs[9].introduction,"本部校区西边出口");
strcpy(G.vexs[10].name,"学院办公楼区");
strcpy(G.vexs[10].introduction,"建有各主要二级学院的办公大楼,如物理院,化工院,冶金院等");
strcpy(G.vexs[11].name,"学生公寓区");
strcpy(G.vexs[11].introduction,"供本部学生住宿");
strcpy(G.vexs[12].name,"中南大学出版社");
strcpy(G.vexs[12].introduction,"出版发行学校主编的各类书刊");
strcpy(G.vexs[13].name,"和平广场");
strcpy(G.vexs[13].introduction,"几个学院大楼围成的空地,可供大型活动用");
for(i=0;i<G.vexnum;i++)
for(j=0;j<G.vexnum;j++)
G.arcs[i][j].adj=INFINITY;
G.arcs[0][10].adj=10;
G.arcs[0][12].adj=50;
G.arcs[1][2].adj=100;
G.arcs[1][5].adj=30;
G.arcs[1][6].adj=300;
G.arcs[1][10].adj=70;
G.arcs[2][7].adj=80;
G.arcs[2][10].adj=80;
G.arcs[2][11].adj=20;
G.arcs[3][4].adj=30;
G.arcs[3][13].adj=100;
G.arcs[4][11].adj=100;
G.arcs[5][8].adj=80;
G.arcs[5][9].adj=50;
G.arcs[6][11].adj=50;
G.arcs[7][10].adj=90;
G.arcs[7][11].adj=50;
G.arcs[7][13].adj=80;
G.arcs[10][13].adj=140;
G.arcs[12][13].adj=30;
for(i=0;i<G.vexnum;i++)
for(j=0;j<G.vexnum;j++)
G.arcs[j][i].adj=G.arcs[i][j].adj;
return G;
}//InitGraph end
void Menu()
{
printf("\n 中南大学校本部导游图\n");
printf(" ┏━━━━━━━━━━━━━━━┓\n");
printf(" ┃ 1.浏览校园全景               ┃\n");
printf(" ┃ 2.查看所有游览路线           ┃\n");
printf(" ┃ 3.选择出发点和目的地         ┃\n");
printf(" ┃ 4.查看景点信息               ┃\n");
printf(" ┃ 5.退出系统                   ┃\n");
printf(" ┗━━━━━━━━━━━━━━━┛\n");
printf("Option-:");
}
void Browser(MGraph *G)
{
int v;
printf("┏━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n");
printf("┃编号┃景点名称 ┃简介 ┃\n");
for(v=0;v<G->vexnum;v++)
printf("┃%-4d┃%-16s┃%-56s┃\n",G->vexs[v].num,G->vexs[v].name,G->vexs[v].introduction);
printf("┗━━┻━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");
}

// 迪杰斯特拉算法来计算出起点到各个顶点之间的最短路径,v0为起点
void ShortestPath_DIJ(MGraph * G)
{
int v,w,i,min,t=0,x,flag=1,v0;
int final[20], D[30], p[30][30];
while(flag)
{
printf("请输入一个起始景点编号:");
scanf("%d",&v0);
if(v0<0||v0>G->vexnum)
{
printf("景点编号不存在!请重新输入景点编号:");
scanf("%d",&v0);
}
if(v0>=0&&v0<G->vexnum)
flag=0;
}
for(v=0;v<G->vexnum;v++)
{
final[v]=0;
D[v]=G->arcs[v0][v].adj;

for(w=0;w<G->vexnum;w++)
p[v][w]=0;
if(D[v]<INFINITY)
{
p[v][v0]=1;p[v][v]=1;
}
}
D[v0]=0;final[v0]=1;
for(i=1;i<G->vexnum;i++)
{
min=INFINITY;
for(w=0;w<G->vexnum;w++)
if(!final[w])
if(D[w]<min){v=w;min=D[w];}
final[v]=1;
for(w=0;w<G->vexnum;w++)
if(!final[w]&&(min+G->arcs[v][w].adj<D[w]))
{
D[w]=min+G->arcs[v][w].adj;
for(x=0;x<G->vexnum;x++)
p[w][x]=p[v][x];
p[w][w]=1;
}
}
for(v=0;v<G->vexnum;v++)
{
if(v0!=v) printf("%s",G->vexs[v0].name);
for(w=0;w<G->vexnum;w++)
{
if(p[v][w]&&w!=v0) printf("-->%s",G->vexs[w].name);
t++;
}
if(t>G->vexnum-1&&v0!=v)printf(" 总路线长%dm\n\n",D[v]);
}
}//ShortestPath_DIJ end
void Floyd(MGraph *G)
{
int v,u,i,w,k,j,z,c,f,flag=1,p[14][14][14],D[14][14];
for(z=0;z<13;z++)
   for(c=0;c<14;c++)
      for(f=0;f<11;f++)
         a[z][c][f]=' ';
for(v=0;v<G->vexnum;v++)
for(w=0;w<G->vexnum;w++)
{
D[v][w]=G->arcs[v][w].adj;
for(u=0;u<G->vexnum;u++)
p[v][w][u]=0;
if(D[v][w]<INFINITY)
{
p[v][w][v]=1;p[v][w][w]=1;
}
}
for(u=0;u<G->vexnum;u++)
for(v=0;v<G->vexnum;v++)
for(w=0;w<G->vexnum;w++)
if(D[v][u]+D[u][w]<D[v][w])
{
D[v][w]=D[v][u]+D[u][w];
for(i=0;i<G->vexnum;i++)
p[v][w][i]=p[v][u][i]||p[u][w][i];
}

while(flag)
{
printf("请输入出发点和目的地的编号:");
scanf("%d%d",&k,&j);
if(k<0||k>G->vexnum||j<0||j>G->vexnum)
{
printf("景点编号不存在!请重新输入出发点和目的地的编号:");
scanf("%d%d",&k,&j);
}
if(k>=0&&k<G->vexnum&&j>=0&&j<G->vexnum)
flag=0;
}
printf("%s",G->vexs[k].name);
f=k;
for(u=0;u<G->vexnum;u++)
if(p[k][j][u]&&k!=u&&j!=u)
{
printf("-->%s",G->vexs[u].name);
if(k==9&&j==10)
{
	a[1][5][4]='.';
	a[1][5][3]='.';
	a[1][5][2]='.';
	a[1][5][1]='.';
	a[1][5][0]='.';
	a[5][9][0]='.';
	a[1][2][1]='.';
	a[1][2][0]='.';
	a[1][10][4]='.';
	a[1][10][3]='.';
	a[1][10][2]='.';
	a[1][10][1]='.';
	a[1][10][0]='.';
	goto shuchu;
}
if(f<=u)
{
for(z=0;z<10;z++)
	a[f][u][z]='.';
if(f==10&&u==11)
{
	for(z=0;z<10;z++)
		a[1][10][z]='.';
	for(z=0;z<6;z++)
		a[1][6][z]='.';
	for(z=0;z<2;z++)
		a[10][11][z]='.';	
	for(z=0;z<5;z++)
		a[2][7][z]='.';
}
if(f==8&&u==10)
{
	a[5][8][0]='.';
}
if(f==7&&u==10)
{
	for(z=0;z<10;z++)
		a[3][13][z]='.';
}
if(f==5&&u==10)
{
	for(z=0;z<6;z++)
		a[1][10][z]='.';
	for(z=0;z<2;z++)
		a[1][2][z]='.';
	for(z=0;z<5;z++)
		a[1][5][z]='.';
	a[5][9][0]='.';
}
if(f==2&&u==11)
{
	a[1][6][5]='.';
	a[1][6][4]='.';
	a[1][6][3]='.';
}
if(f==3&&u==4)
{
	a[4][11][2]='.';
	a[4][11][1]='.';
	a[4][11][0]='.';
}
if(f==1&&u==2)
{
	a[1][10][9]='.';
	a[1][10][8]='.';
	a[1][10][7]='.';
	a[1][10][6]='.';
	a[1][10][5]='.';
}
if(f==1&&u==9)
{
	a[1][5][4]='.';
	a[1][5][3]='.';
	a[1][5][2]='.';
	a[1][5][1]='.';
	a[1][5][0]='.';
	a[5][9][0]='.';
}
if(f==4&&u==7)
{
	a[3][4][3]='.';
	a[3][4][2]='.';
	a[3][4][1]='.';
	a[3][4][0]='.';
}
if(f==7&&u==11)
{
	a[4][11][0]='.';
	a[4][11][1]='.';
	a[4][11][2]='.';
	a[3][4][0]='.';
	a[3][4][1]='.';
	a[3][4][2]='.';
	a[3][4][3]='.';
}
if(f==2&&u==10)
{
	a[1][6][2]='.';
	a[1][6][1]='.';
	a[1][6][0]='.';
	for(z=0;z<10;z++)
		a[f-1][u][z]='.';
}
if(f==0&&u==2)
{
	a[0][10][0]='.';
}
if(f==0&&u==1)
{
	a[0][10][0]='.';
}
f=u;
}



else
{
	c=f;
	f=u;
	u=c;
	for(z=0;z<10;z++)
		a[f][u][z]='.';
if(f==2&&u==11)
{
	a[1][6][5]='.';
	a[1][6][4]='.';
	a[1][6][3]='.';
}
if(f==8&&u==10)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -