• 大小: 2KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: C/C++
  • 标签: dfs  图论  两点  路径  

资源简介

求两点直接所有路径代码,有注释 花了很长时间搞懂做好的。。。。。

资源截图

代码片段和文件信息

// DFS.cpp : Defines the entry point for the console application.
//
// bfs.cpp : Defines the entry point for the console application.
//

#include “stdafx.h“
#include 
#include 
#include 
#include 
using namespace std;

stack not_explored;
int *discovered;
class EdgeNode;
typedef EdgeNode * EdgeList;
//边链表
class EdgeNode
{
public:
int vertexNum; //边界点在定点表中的下标
int weight; //权值
EdgeNode * nextEdgeNode; //指针字段,指向下一个链结点
};
//顶点表
class Vertex
{
public:
char vertex;                 //顶点信息
EdgeList edgeList;        //边链表头指针
};
class GraphList
{
public:
int n;                          //图中定点个数
Vertex *vertexes;   //顶点表
};
int DFS_Search(int nGraphList gl)
{
if (n <= 1)
{
return 0;
}
else
{
int node_to_explore;
bool flag ;
EdgeNode *p = new EdgeNode();
not_explored.push(0);
discovered[0] = 1;
while(!not_explored.empty())
{
flag = false;
node_to_explore = not_explored.top();
//not_explored.push();注意不要从栈内删除;因为回溯时候要用到此步为关键点
//p = new EdgeNode();
p = gl.vertexes[node_to_explore].edgeList;
if (p)
{

while (p)
{
if (discovered[p->vertexNum] =

评论

共有 条评论