最近在学数据结构,看到图的遍历小有疑惑,便去实现了一番。。。。
以下是用C++ 实现:
#include
<iostream>
#include
<queue> //队列定义,用于广度递归查询
#include
<stack> //栈的定义, 用于深度非递归查询
#include
<stdlib.h>
#include
<cstdio> //方便调用c语言函数
#define
MAX
100 //最大值
using
namespace
std
;
typedef
struct
{
int
edges[MAX][MAX];
int
n;
int
e;
}MGraph; //图的定义
bool
visited[MAX];
void
craeteMGraph
(MGraph
&
G) //初始化图
{
int
i, j;
int
s, t;
int
v;
for
(i
=
0
; i
<
G.
n
; i
++
) //将边清空
{
for
(j
=
0
; j
<
G.
n
; j
++
)
{
<