特点:
- 顶点表示活动
- 边表示活动的先后次序,边没有权值
- 没有回路的有向图
结构体定义:
typedef struct node //边表 { int adjvex; struct node* next; }ArcNode; typedef struct //顶点表 { int data; int count; //记录顶点的入度 ArcNode* first; }VerNode; typedef struct //邻接表 { VerNode adjList[MaxVertices]; int n,e; }AdjList;
AOV拓扑排序代码:
void Topsort(AdjList *G)
{
int i,j;
int Stack[MaxVertices],top = -1;
ArcNode *p;
for(i=0;i<G->n;i++) //让所有入度为0的顶点入栈
{
if(G->adjList[i].count == 0)
Stack[++top] = G->adjList[i].data;
}