DFS
完整源码
DFS.cpp
// DFS.cpp
#include <iostream>
using namespace std;
bool marked[10];
int G[10][10];
int V,E;
int count;
void dfs(int v) {
count++;
int level;
level = count;
for(int i = 0 ;i < level ;i++)
cout << " ";
cout << "DFS " << v << " start : " << endl;
marked[v] = true;
for(int i = 0; i < V;i++)
if(!marked[i] && G[v][i]) dfs(i);
for(int i = 0 ;i < level ;i++)
cout << " ";
cout << "DFS " << v << " end. " << endl;
}
void readData() {
for(int i = 0; i < 10;i++)
for(int j = 0; j < 10; j&