資源簡介
求兩點直接所有路徑代碼,有注釋
花了很長時間搞懂做好的。。。。。
代碼片段和文件信息
//?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]?=
評論
共有 條評論