|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include"type.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
|
功能:查找某一个城市的信息
|
|
|
|
|
输入:城市的编号
|
|
|
|
|
输出:城市的编号,名称以及简介
|
|
|
|
|
***********************/
|
|
|
|
|
int search(MatGrath &G)
|
|
|
|
|
{ int a;
|
|
|
|
|
int flag=1;
|
|
|
|
|
printf("请输入您要查询的城市编号\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
while(flag)
|
|
|
|
|
{
|
|
|
|
|
if(a<=0||a>G.vexnum)
|
|
|
|
|
{
|
|
|
|
|
printf("编号不存在,请重新输入\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ flag=0;
|
|
|
|
|
|
|
|
|
|
printf("编号 景点名称 简介 \n");
|
|
|
|
|
printf(" %-4d %-16s%-58s\n",G.vexs[a].no,G.vexs[a].sight,G.vexs[a].introduction);
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
|
功能:连接任意两个点
|
|
|
|
|
输入:两个点的编号
|
|
|
|
|
输出:无
|
|
|
|
|
***********************/
|
|
|
|
|
void addbian(MatGrath &G)
|
|
|
|
|
{ int b,c,d;
|
|
|
|
|
int i,j;
|
|
|
|
|
printf("请输入你要增加的边的两个点\n");
|
|
|
|
|
scanf("%d %d",&b,&c);
|
|
|
|
|
printf("请输入你要增加的边的权值\n");
|
|
|
|
|
scanf("%d",&d);
|
|
|
|
|
for (i=1; i<=G.vexnum;i++)
|
|
|
|
|
for (j=1;j<=G.vexnum;j++)
|
|
|
|
|
{
|
|
|
|
|
if((G.arc[i][j].length==INF)&&(i==b)&&(j==c))
|
|
|
|
|
{
|
|
|
|
|
G.arc[i][j].length=G.arc[j][i].length=d;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/***********************
|
|
|
|
|
功能:增加一个点
|
|
|
|
|
输入:与其他点的边的权值
|
|
|
|
|
输出:无
|
|
|
|
|
***********************/
|
|
|
|
|
void adddian(MatGrath &G)
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
int b;
|
|
|
|
|
int c;
|
|
|
|
|
int d;
|
|
|
|
|
char e[10]; //地点名
|
|
|
|
|
char f[100]; //地点介绍
|
|
|
|
|
int flag;
|
|
|
|
|
printf("请输入该城市的编号\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
G.vexs[a].no=a;
|
|
|
|
|
while(flag)
|
|
|
|
|
{
|
|
|
|
|
if(a>=0&&a<=G.vexnum)
|
|
|
|
|
{
|
|
|
|
|
printf("编号已经存在,请重新输入\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
G.vexs[a].no=a;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
flag=0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("请输入你要连接的点权值和所需费用\n");
|
|
|
|
|
scanf("%d",&b);
|
|
|
|
|
scanf("%d",&c);
|
|
|
|
|
scanf("%d",&d);
|
|
|
|
|
G.arc[a][b].money=G.arc[a][b].money=c;
|
|
|
|
|
G.arc[a][b].length=G.arc[b][a].length=d;
|
|
|
|
|
scanf("%s",G.vexs[a].sight);
|
|
|
|
|
scanf("%s",G.vexs[a].introduction);
|
|
|
|
|
G.vexnum++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
|
功能:修改城市信息
|
|
|
|
|
输入:要修改的城市编号,以及修改后的城市信息
|
|
|
|
|
输出:无
|
|
|
|
|
***********************/
|
|
|
|
|
void modify(MatGrath &G)
|
|
|
|
|
{ int a;
|
|
|
|
|
int flag=1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("请输入你要修改的城市的编号\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
while(flag)
|
|
|
|
|
{
|
|
|
|
|
if(a<=0||a>G.vexnum)
|
|
|
|
|
{
|
|
|
|
|
printf("编号不存在,请重新输入\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
flag=0;
|
|
|
|
|
}
|
|
|
|
|
printf("请输入你要修改的信息\n");
|
|
|
|
|
scanf("%s",G.vexs[a].sight);
|
|
|
|
|
|
|
|
|
|
scanf("%s",G.vexs[a].introduction);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/***********************
|
|
|
|
|
功能:输出所有的城市信息
|
|
|
|
|
输入:无
|
|
|
|
|
输出:输出所有的城市信息
|
|
|
|
|
***********************/
|
|
|
|
|
int display(MatGrath &G)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
printf("城市编号 城市名称 城市介绍\n");
|
|
|
|
|
for (i=1; i<=G.vexnum;i++)
|
|
|
|
|
{
|
|
|
|
|
printf("% -9d % -10s %-15s\n",G.vexs[i].no,G.vexs[i].sight,G.vexs[i].introduction);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
/***********************
|
|
|
|
|
功能:用深度遍历输出城市信息
|
|
|
|
|
输入:无
|
|
|
|
|
输出:输出所有的城市信息
|
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
|
|
bool visited[MAXV];
|
|
|
|
|
int DFS(MatGrath &G,int m)//深度优先搜索
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
printf("%d %s %s\n",G.vexs[m].no,G.vexs[m].sight,G.vexs[m].introduction);
|
|
|
|
|
visited[m]=true;
|
|
|
|
|
for(i=1;i<=G.vexnum;i++)
|
|
|
|
|
{
|
|
|
|
|
if(G.arc[m][i].length!=INF&&visited[i]==false)
|
|
|
|
|
{
|
|
|
|
|
DFS(G,i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
|
功能:删除某一个边
|
|
|
|
|
输入:边两边的城市编号
|
|
|
|
|
输出:无
|
|
|
|
|
***********************/
|
|
|
|
|
int delet(MatGrath &G,int y,int x)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
G.arc[x][y].length=G.arc[y][x].length=INF;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|