当一个AOV网用邻接表表示时可按下列方法进行拓扑排序
().查邻接表中入度为______的顶点并进栈
().若栈不空则①输出栈顶元素Vj并退栈②查Vj的直接后继Vk对Vk入度处理处理方法是______
().若栈空时输出顶点数小于图的顶点数说明有______否则拓扑排序完成【南京理工大学 二 (分)】
.已知图的邻接表结构为
CONST vtxnum={图的顶点数}
TYPE vtxptr=vtxnum;
arcptr=^arcnode;
arcnode=RECORD adjvex:vtxptr; nextarc:arcptr END;
vexnode=RECORD vexdata:{和顶点相关的信息}firstarc:arcptr END;
adjlist=ARRAY[vtxptr]OF vexnode;
本算法是实现图的深度优先遍历的非递归算法其中使用一个顺序栈stack栈顶指针为topvisited为标志数组
PROC dfs(g:adjlist;v:vtxptr);
top=; write(v); visited[v]:=ture; p:=g[v]firstarc;
WHILE (top<>)OR(p<>NIL)DO
[WHILE()_______DO
[v:=p^adjvex;
IF()_______ THEN p:=p^nextarc
ELSE [write(v); visited[v]:=true; top:=top+; stack[top]:=p; ()_______] ]
IF top<> THEN[p:=stack[top]; top:=top; ()_______]
]
ENDP 【同济大学 二 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []