java 图的深度遍历 邻接矩阵

public class DeepthTraversal

{

public static void deepTravel(int[][] a, int[] color, int k)

{

System.out.println(k);

color[k] = 1;

for(int i = 0; i < a[k].length; i ++)

{

if(a[k][i] == 1 && color[i] == 0)

{

deepTravel(a, color, i);

}

}

}

public static void main(String[] args)

{

int[][] a = {{0,1,1,1,0},{1,0,1,1,1},{1,1,0,0,0},{1,1,0,0,0},{0,1,0,0,0}};

int[] color = new int[a.length];

deepTravel(a, color, 0);

}

}

    原文作者:数据结构之图
    原文地址: https://blog.csdn.net/cgguopengfei/article/details/52839651
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞