DFS算法:遍历任意两点之间所有路径并输出.docVIP

  • 22
  • 0
  • 约6.86千字
  • 约 10页
  • 2017-06-03 发布于湖北
  • 举报

DFS算法:遍历任意两点之间所有路径并输出.doc

DFS算法:遍历任意两点之间的所有路径并输出 代码大部分都是从数据结构书上来的,水平有限仅供参考!希望对课程设计要用到这个算法的同学有帮助 先看运行结果: 起点1,终点7 基本代码都是从数据结构书上抄来的,重点看红字。 全部源代码 //mian的实现 #include stdafx.h #include iostream #include assert.h #include graph.h #include Graphm.h #include AList.h using namespace std; void PrintPath(AListint* path){ //打印路径 int L=path-Length(); int temp=-1; for(int i=0;iL;i++) { path-setPos(i); path-getValue(temp); couttemp; if(i!=L-1) cout; } coutendl; } void DFS(Graph* G,int v,int end,AListint* path){ G-setMark(v,VISITED); //标记为已访问,防止路径重复 path-append(v); //记录节点 if(v==end)

文档评论(0)

1亿VIP精品文档

相关文档