# 图的深度遍历没有进入递归函数

• 147
``````#include<iostream>
using namespace std;
const int MaxSize = 10;
template<class T>
class MGraph{

public :
MGraph(T a[], int n, int e);//n个顶点e条边
void DFSTraverse(int v);
void visited(int max);

private:
T vertex[MaxSize];
int arc[MaxSize][MaxSize];
int vertexNum, arcNum;
int arrvisited[6];
//arrvisited[] = {0,0,0,0,0,0}
};
template<class T>MGraph<T>::MGraph(T a[], int n, int e){
int i = 0, j = 0;
vertexNum = n; arcNum = e;
for ( i = 0; i < vertexNum; i++)
vertex[i] = a[i];
for ( i = 0; i < vertexNum;i++)
for (j = 0; j < vertexNum; j++)
arc[i][j] = 0;
cout << "请输入每条边所依附的两个顶点的序号:" << endl;
for (int k = 0; k < arcNum; k++){
cin >> i >> j;
arc[i][j] = 1;
arc[j][i] = 1;
}
cout << "执行此处3" << endl;

for (int i = 0; i < 6; i++){ arrvisited[i] = 0; }
}
/*
template<class T>void MGraph<T>::visited(int max){
cout << "执行此处2" << endl;
for (int i = 0; i < max; i++){
arrvisited[i] = 0;
}
}
*/

template<class T>void MGraph<T>::DFSTraverse(int v){
cout << "执行此处1" << endl;
cout << vertex[v];
arrvisited[v] = 1;
for (int j = 0; j < vertexNum; j++){
cout << "准备进入递归了" << endl;
if (arc[v][j] == 1 && arrvisited[j] == 0) DFSTraverse(j);
cout << "真的进入递归了" << endl;
}

}
``````

###### 你尚未登录，登录后可以
• 和开发者交流问题的细节
• 关注并接收问题和回答的更新提醒
• 参与内容的编辑和改进，让解决方法与时俱进