include[HTML_REMOVED]
using namespace std;
define MaxVex 100
typedef char VexType;
typedef int EdgeType;
typedef struct{
VexType node[MaxVex];
EdgeType edges[MaxVex][MaxVex];
int vexnum,edgenum;
}AdjMatrix;
//邻接矩阵定义
typedef struct EdgeNode{
int adjvex;//邻接点下标
struct EdgeNode *next;
}EdgeNode;//边结点定义
typedef struct VexNode{
VexType data;
EdgeNode * firstedge;
}VexNode;//图结点定义
typedef struct{
VexNode vertex[MaxVex];
int vexnum,edgenum;
}AdjList;//邻接表定义
int visited[MaxVex];
void dfs(AdjMatrix G,int n);
void dfs_main(AdjMatrix G){
for(int i=1;i<=G.vexnum;i) visited[i]=0;
for(int i=1;i<=G.vexnum;i){
if(visited[i]==0){
dfs(G,i);
}
}
}
void dfs(AdjMatrix G,int n){
visited[n]=1;
cout<<n;
for(int i=1;i<=G.vexnum;i++){
if(G.edges[n][i]==1&&visited[i]==0){
dfs(G,i);
}
}
}
int main(){
AdjMatrix G;
G.vexnum=9;
G.edgenum=10;
for(int i=1;i<=MaxVex-1;i){
for(int j=1;j<=MaxVex-1;j)
G.edges[i][j]=0;
}
G.edges[1][2]=1;G.edges[2][1]=1;
G.edges[1][4]=1;G.edges[4][1]=1;
G.edges[1][5]=1;G.edges[5][1]=1;
G.edges[2][4]=1;G.edges[4][2]=1;
G.edges[2][3]=1;G.edges[3][2]=1;
G.edges[3][6]=1;G.edges[6][3]=1;
G.edges[4][7]=1;G.edges[7][4]=1;
G.edges[5][7]=1;G.edges[7][5]=1;
G.edges[7][8]=1;G.edges[8][7]=1;
G.edges[8][9]=1;G.edges[9][8]=1;
cout<<”DFS”<<endl;
cout<<”123647589”<<endl;
dfs_main(G);
//邻接矩阵实现bfs
}