假设有向图采用邻接表表示法,其定义如下:
typedef struct{
VertexNode adjlist[MaxVertexNum]:
int n,e;//图的当前顶点数和弧数
}ALGraph;//邻接表类型
其中顶点表结点 VertexNode结构为: vertex firstedge
边表结点 EdgeNode结构为:adjvex next
下列算法f33的功能是,对以邻接表表示的有向图进行拓扑排序
(1)阅读算法f33,并在空缺处填入合适的内容,使其成为一个完整的算法
(2)对于题33图所示的邻接表,将执行算法f33后的topo[]结果填入给定的数组中
void f33(ALGraph G, int topo []
{
int i.j,k,count=0:
int indegree[MaxVertexNum];
EdgeNode*p//为指向边表结点的指针
3D
Queue Q://Q为队列
FindIndegree(G, indegree);//求各顶点的人度,并置于入度向量indegree
InitQueue(&Q);
for(i=0: i if(! indegree[i])En Queue(&Q,i); while(!QueueEmpty(&Q)) { j=① topo[i]=++count; for(p=G. adjlist[]. firstedge; P: P=p->next) { k=p->adjvex; if--indegree-[k]② } ifcount } (1)① ② (2)topo
订单号:
遇到问题请联系在线客服
订单号:
遇到问题请联系在线客服