图的深度优先遍历(用邻接矩阵表示图)

图的深度优先遍历(用邻接矩阵表示图)

#include <stdio.h>
#include <stdlib.h>
void bianli(bool students[8][8],int student[8],int i,bool temp[8])
{
    printf("%d\n",student[i]);
    temp[i]=0;
    for(int j=0;j<8;j++)
    {
        if(students[i][j])
        {
            if(temp[j])
                bianli(students,student,j,temp);
        }
    }
}
int main()
{
    int student[8]={0,1,2,3,4,5,6,7};
    bool students[8][8]={0,1,0,1,1,0,0,0,
                         1,0,1,0,1,0,0,0,
                         0,1,0,0,0,1,0,0,
                         1,0,0,0,0,0,1,0,
                         1,1,0,0,0,0,1,0,
                         0,0,1,0,0,0,0,0,
                         0,0,0,1,0,0,0,1,
                         0,0,0,0,0,0,1,0};
    puts("OK");
    bool temp[8]={1,1,1,1,1,1,1,1};
    bianli(students,student,0,temp);
    return 0;
}
/* 测试数据 0 1 0 3 0 4 1 0 1 2 1 4 2 1 2 5 3 0 3 6 4 0 4 1 4 6 5 2 6 3 6 7 7 6 */
    原文作者:数据结构之图
    原文地址: https://blog.csdn.net/lhdalhd1996/article/details/51377475
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞