觉得我这种方法还比较清晰易懂,虽然算不上哪种方法,但确实每个点都能遍历到.
实际上有怎么弄得吗......
typedef struct Arcs{
int AdjVex;
int Weight;
struct Arcs *NextArc;
}ArcType;
typedef struct{
int Vex[MaxVex];
ArcType *FirstArc[MaxVex];
int VexNum;
}ALGraph;
//-----------------------------------------------------------------------
void GraphTraver(ALGraph AG) //图的遍历;
{
int i,Visited[MaxVex] = {0};
ArcType *p = NULL;
for(i = 1;i <= AG.VexNum;i++)
{
if(Visited[i] != 1)
{
printf("%2d ",AG.Vex[i]);
Visited[AG.Vex[i]] = 1;
}
p = AG.FirstArc[i];
while(p != NULL)
{
if(Visited[p->AdjVex] != 1)
{
printf("%2d ",p->AdjVex);
Visited[p->AdjVex] = 1;
}
p = p->NextArc;
}
}
}
//-----------------------------------------------------------------------
看看这种图的遍历...