数据结构teachingmaterials7.ppt

  1. 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据结构teachingmaterials7

Application using graphs themselves as data structures 2. Topological Sorting / 拓扑排序 实现算法: 假设用混合模式的存储结构,且产生的拓扑排序结果序列为 Vertex toporder[MaxVertex]; /*DepthTopSort: generate depth-first topological order Pre: G is a directed graph with no cycles implemented with a contiguous list of vertices and linked adjacency lists. Post: The function makes a depth-first traversal of G and generates the resulting topological order in the array T. Uses: RecDepthSort performs the recursive depth-first traversal. */ void DepthTopSort ( Graph *G, Toporder T ) { Vertex v; //next vertex whose successors are to be ordered int place; //next position in the topological order to be filled for ( v = 0; v G-n; v++ ) visited[v] = FALSE; place = G-n-1; for ( v = 0; v G-n; v++ ) if ( !visited[v] ) RecDepthSort(G, v, place, T); } //Breadth-First Algorithm to be wished to consider after class … to be continued 算法分析: 时间复杂性为O(n+e). Application using graphs themselves as data structures 2. Topological Sorting / 拓扑排序 实现算法: 假设用混合模式的存储结构,且产生的拓扑排序结果序列为 Vertex toporder[MaxVertex]; /* RecDepthSort: performs the recursion for DepthTopSort Pre: v is a vertex of the graph G and places is the next location in the topological order T to be determined (starting from the end of the final ordered list). Post: The procedure puts all the successors of v and finally v itself into the toplogical order T in depth-first order. Uses: Global array visited and RecDepthSort recursively. */ void RecDepthSort ( Graph *G, int v, int *place, Toporder T ) { Vertex curvertex; //vertex adjacent to v Edge *curedge; //traverses list of vertices adjacent to v visited[v] = TRUE; while ( curedge ) { curvertex = curedge-endpoint; //find the first vertex succeeding to v if ( !visited[curvertex] ) RecDepthSort[G, Curvertex, place, T); //order the successors of curvertex curedge=curedge-nextedge; } //go on to next immediate suc

文档评论(0)

qwd513620855 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档