資源簡介
數據結構圖的知識,校園導游圖,
可以查詢所有路徑和最短路徑,自己寫的算法。

代碼片段和文件信息
#include?“stdio.h“
#include?“stdlib.h“
#include?“string.h“
#define?Max?20
struct?Path
{int?Pathway[Max][Max];
int?Pathlength[Max];
int?length;
};
struct?Stack
{int?a[Max];
int?top;
};
struct?ArcNode
{int?adjvex;
int?length;
ArcNode?*nextarc;
};
struct?VNode
{
char?name[20];
char?info[100];
ArcNode?*firstarc;
};
struct?Graph
{VNode?vertices[Max];
int?vexnumarcnum;
};
void?InitGraph(Graph?&g)
{g.vexnum=0;
g.arcnum=0;
}
void?InitStack(Stack?&S)
{S.top=0;}
void?Push(Stack?&Sint?x)
{S.a[S.top]=x;
S.top++;
}
void?GetTop(Stack?&Sint?&x)
{x=S.a[S.top-1];
}
bool?Pop(Stack?&Sint?&x)
{if(S.top<0)
return?0;
else
{x=S.a[--S.top];
return?1;
}}
bool?InStack(Stack?Sint?x)
{for?(int?i=0;i {if?(S.a[i]==x)
{return?1;
}
}
return?0;
}
bool?LocateVex(Graph?gchar?*uint?&x)
{for?(int?i=0;i {if(!strcmp(g.vertices[i].nameu))
{x=i;return?1;
}
}
return?0;
}
void?GetVex(Graph?gint?iVNode*?&v)
{if?(i {v=&g.vertices[i];
}
v=NULL;
}
void?InsertVex(Graph?&gVNode?v)
{strcpy(g.vertices[g.vexnum].namev.name);
strcpy(g.vertices[g.vexnum].infov.info);
g.vertices[g.vexnum].firstarc=NULL;
g.vexnum++;
}
void?InserArc(Graph?&gint?vint?wint?length)
{ if(v>=g.vexnum||w>=g.vexnum)
exit(0);
else
{ArcNode?*temp=(ArcNode?*)malloc(sizeof(ArcNode))*temp2=(ArcNode?*)malloc(sizeof(ArcNode));
temp->length=length;temp->adjvex=w;temp->nextarc=NULL;
temp2->length=length;temp2->adjvex=v;temp2->nextarc=NULL;
if(!g.vertices[v].firstarc)
g.vertices[v].firstarc=temp;
else
{temp->nextarc=g.vertices[v].firstarc;
g.vertices[v].firstarc=temp;
}
if(!g.vertices[w].firstarc)
g.vertices[w].firstarc=temp2;
else
{temp2->nextarc=g.vertices[w].firstarc;
g.vertices[w].firstarc=temp2;
}
g.arcnum++;
}
}
bool?GetNextVNode(Graph?gint?vint?wArcNode*?&next)
{if(v==w)
{next=g.vertices[v].firstarc;return?1;}
else
{ArcNode?*temp=g.vertices[v].firstarc;
while?(temp&&temp->adjvex!=w)
temp=temp->nextarc;
next=temp->nextarc;
return?1;
}
return?0;
}
//用于保存路徑的函數
void?InitPath(Path?&pa)
{for?(int?i=0;i {pa.Pathlength[i]=0;pa.Pathway[i][0]=0;}
pa.length=0;
}
void?CopyPath(Path?&paStack?S)
{pa.Pathway[pa.length][0]=S.top;
for(int?i=0;i pa.Pathway[pa.length][i+1]=S.a[i];
pa.length++;
}
Path?FindPath(Graph?gint?vint?w)
{Stack?S;Path?Pa;int?xy;
int?*record=(int?*)malloc(g.vexnum*sizeof(int));
for?(int?i=0;i {record[i]=i;
}
InitStack(S);InitPath(Pa);
VNode?temp;ArcNode?*next;
temp=g.vertices[v];
Push(Sv);
GetNextVNode(gvvnext);
record[v]=next->adjvex;
while(S.top)
{
if(next)
{x=next->adjvex;
if(!InStack(Sx))
{Push(Sx);
if(x==w)
{
CopyPath(PaS);
Pop(Sy);
GetTop(Sy);
GetNextVNode(gyrecord[y]next);
record[y]=next?next->adjvex:y;
}
else
GetNextVNode(gxrecord[x]next);
record[x]=next?next->adjvex:x;
}
else
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????35164??2011-12-10?18:27??校園導游圖\Debug\main.obj
?????文件??????33792??2011-12-12?12:24??校園導游圖\Debug\vc60.idb
?????文件??????53248??2011-12-10?18:27??校園導游圖\Debug\vc60.pdb
?????文件?????180297??2011-12-10?18:27??校園導游圖\Debug\校園導游圖.exe
?????文件?????370140??2011-12-10?18:27??校園導游圖\Debug\校園導游圖.ilk
?????文件?????226100??2011-12-10?16:42??校園導游圖\Debug\校園導游圖.pch
?????文件?????484352??2011-12-10?18:27??校園導游圖\Debug\校園導游圖.pdb
?????文件???????8384??2011-12-10?18:27??校園導游圖\main.cpp
?????文件???????4337??2011-12-05?21:53??校園導游圖\校園導游圖.dsp
?????文件????????530??2011-12-05?21:15??校園導游圖\校園導游圖.dsw
?????文件??????50176??2011-12-11?00:14??校園導游圖\校園導游圖.ncb
?????文件??????48640??2011-12-11?00:14??校園導游圖\校園導游圖.opt
?????文件???????1553??2011-12-10?18:27??校園導游圖\校園導游圖.plg
?????目錄??????????0??2011-12-29?17:49??校園導游圖\Debug
?????目錄??????????0??2011-12-29?17:49??校園導游圖
-----------?---------??----------?-----??----
??????????????1496713????????????????????15
評論
共有 條評論