数据结构中用邻接矩阵方式储存图，广度优先，深度优先遍历

/**用邻接矩阵的方式来储存图，用广度优先方式进行遍历 **/

#include "stdio.h"
#define max_matrix 10

int visited[max_matrix],matrix[max_matrix][max_matrix];
int n;
int board_traverse();

int main()
{
int i,j;
scanf("%d",&n);
if (n<1)
{
printf("n must be >1\n");
exit(0);
}
if (n>max_matrix)
{
printf("n must be <%d\n",max_matrix);
exit(0);
}
for (i=0;i<n;i++)
{
visited[i]=0;
for (j=0;j<n;j++)
matrix[i][j] = 0;
}
while (scanf("%d %d",&i,&j)==2)
{
matrix[i-1][j-1]=1;
}

for(i=0;i<n;i++)
{
for (j=0;j<n;j++)
printf("%d ",matrix[i][j]);
printf("\n");
}
printf("1 ");
board_traverse(0);
}

int board_traverse()
{
int temp,i,j,ma_j,ma_i;
for (ma_i=0;ma_i<n;ma_i++)
for (ma_j=ma_i;ma_j<n;ma_j++)
if (matrix[ma_i][ma_j] && visited[ma_j]==0)
{
printf("%d ",ma_j+1);
visited[ma_j]=1;
}
}

/**用邻接矩阵的方式来储存图，用深度优先方式进行遍历 **/

#include "stdio.h"
#define max_matrix 10

int visited[max_matrix],matrix[max_matrix][max_matrix];
int n;
int deep_traverse(int);

int main()
{
int i,j;
scanf("%d",&n);
if (n<1)
{
printf("n must be >1\n");
exit(0);
}
if (n>max_matrix)
{
printf("n must be <%d\n",max_matrix);
exit(0);
}
for (i=0;i<n;i++)
{
visited[i]=0;
for (j=0;j<n;j++)
matrix[i][j] = 0;
}
while (scanf("%d %d",&i,&j)==2)
{
matrix[i-1][j-1]=1;
}

for(i=0;i<n;i++)
{
for (j=0;j<n;j++)
printf("%d ",matrix[i][j]);
printf("\n");
}
printf("1->");
deep_traverse(0);
}

int deep_traverse(int ma_i)
{
int temp,i,j,ma_j;
ma_j = ma_i;
while (ma_j<n)
{
if (matrix[ma_i][ma_j] && visited[ma_j]==0)
{
printf("%d->",ma_j+1);
visited[ma_j]=1;
deep_traverse(ma_j);
}
ma_j++;
}
}