|
|
@ -101,21 +101,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
## 3.1 核心数据结构的实现
|
|
|
|
## 3.1 核心数据结构的实现
|
|
|
|
|
|
|
|
|
|
|
|
描述数据结构的实现方法。
|
|
|
|
利用循环结构实现查找某一个城市的信息
|
|
|
|
|
|
|
|
如下:
|
|
|
|
可以配合程序代码加以说明。如:
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
}
|
|
|
|
struct LNode {
|
|
|
|
|
|
|
|
E data; // 数据元素
|
|
|
|
|
|
|
|
LNode *next; // 指向下一个结点的指针
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
利用深度遍历实现输出城市信息
|
|
|
|
|
|
|
|
如下:
|
|
|
|
|
|
|
|
|
|
|
|
对该数据结构的特点进行分析。
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 3.2 核心算法的实现
|
|
|
|
## 3.2 核心算法的实现
|
|
|
|