資源簡介
這個是我們做課程設(shè)計(jì)時做的,感覺是自己做的比較好的一次,所以上傳來給大家分享一下,有點(diǎn)獻(xiàn)丑了
代碼片段和文件信息
#include
#include
#include
#define?MAX_VERTEX_NUM??100????????/*最大頂點(diǎn)數(shù)為100*/
typedef?int?VertexType;
/*表結(jié)點(diǎn)*/
typedef?struct?ArcNode
{
int?adjvex;?
int?lon;
struct?ArcNode??*?nextarc;?????
}ArcNode;
/*頭結(jié)點(diǎn)*/
typedef?struct?VNode
{?????????????
VertexType?data;?
ArcNode??*?firstarc;??????????
}VNodeAdjList[MAX_VERTEX_NUM];
typedef?struct
{
AdjList?vertices;??????????????
int?vexnumarcnum;??????????????
}ALGraph;
//地名
typedef?struct?Place
{?????????????
char?name[20];??????????
}PlacePL[20];
int?daohang(ALGraph?Gint?nint?qint?Lj[20]int?M)//導(dǎo)航函數(shù)(圖,起點(diǎn),終點(diǎn),路徑數(shù)組,范圍)
{
ArcNode?*s*d*e;
int?l=0x;
s=G.vertices[n-1].firstarc;
if(!s) //死路,返回?zé)o限遠(yuǎn)
l=1000;
else
{
Lj[0]=G.vertices[n-1].data;
while(s) //孤立起始點(diǎn)
{
x=s->adjvex;
if(x==q)
{
Lj[1]=q;
l=s->lon;
return?l;
}
d=G.vertices[x-1].firstarc;
if(d->adjvex==n)
G.vertices[x-1].firstarc=d->nextarc;
else
{
while(d->nextarc)
{
if(d->nextarc->adjvex==n)
{
d->nextarc=d->nextarc->nextarc;
break;
}
d=d->nextarc;
}
}
s=s->nextarc;
}
int?L[20]={0}i=0z;
e=G.vertices[n-1].firstarc;
while(e)
{
if(Mlon)
e=e->nextarc;
else
break;
}
if(e)
{
l=daohang(Ge->adjvexqLM-e->lon)+e->lon;
for(int?j=0;j<20;j++)
Lj[j+1]=L[j];
e=e->nextarc;
}
while(e)
{
if(M>=e->lon)
{
if((z=daohang(Ge->adjvexqLM-e->lon)+e->lon) {
l=z;
for(int?j=0;j<20;j++)
Lj[j+1]=L[j];
}
}
e=e->nextarc;
}
}
if(l==0)
l=1000;
return?l;
}
void?get(ALGraph?&Gint?BC[400])//獲得地圖(無向圖)
{
ArcNode?*s;
FILE?*fp;
if((fp=fopen(“file““rb“))==NULL)
{
printf(“can?not?open?file\n“);
return?;
}
fread(BC
評論
共有 條評論