/**
 * Company
 * Copyright (C) 2014-2017 All Rights Reserved.
 */
package com.cwenao.datastructure;

import com.cwenao.util.DrawGraphForSearch;
import com.cwenao.util.Vertexes;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author cwenao
 * @version $Id BreadthFirstSearchPath.java, v 0.1 2017-07-07 8:17 cwenao Exp $$
 */
public class BreadthFirstSearchPath {

    private static final int maxVertexes = 5;
    private static Vertexes[] vertexes;
    private static int[][] adjacent;

    public static void entrySearar (Integer start) {
        Queue queue = new ArrayDeque();
        queue.add(start);

        while (!queue.isEmpty()) {
            int x = (int) queue.poll();
            printVertexe(x);
            for(int i =1;i<maxVertexes;i++) {
                if (adjacent[x][i] != 1 && vertexes[x].getVisited() == false) {
                    vertexes[x].setVisited(true);
                    queue.offer(i);
                }
            }
        }
    }

    private static void printVertexe(int i) {
        System.out.println(vertexes[i].getVertex() + " ");
    }
    public static void main(String[] args) {
        DrawGraphForSearch drawGraphForSearch = new DrawGraphForSearch(maxVertexes);

        char[] ver = {'A','B','C','D','E'}; //,'D','E','F','G','H','I'

        vertexes = drawGraphForSearch.getVertexes();

        for(int i=0;i<vertexes.length;i++) {
            Vertexes vertexesX = new Vertexes(ver[i]);
            vertexes[i] = vertexesX;
        }
        drawGraphForSearch.addEdge(0,1);
        drawGraphForSearch.addEdge(0,2);
        drawGraphForSearch.addEdge(2,3);
        drawGraphForSearch.addEdge(3,5);
        drawGraphForSearch.addEdge(5,8);

        drawGraphForSearch.setVertexes(vertexes);
        adjacent = drawGraphForSearch.getAdjacent();
        entrySearar(0);

    }
}


@@ -415,17 +415,17 @@
 texes = 
-5
+9
 ;%0A    pr
@@ -707,25 +707,39 @@
     
-printVertexe(x
+vertexes%5Bx%5D.setVisited(true
 );%0A
+%0A
     
@@ -757,17 +757,17 @@
 (int i =
-1
+0
 ;i%3CmaxVe
@@ -815,17 +815,17 @@
 t%5Bx%5D%5Bi%5D 
-!
+=
 = 1 && v
@@ -832,17 +832,17 @@
 ertexes%5B
-x
+i
 %5D.getVis
@@ -856,24 +856,61 @@
 == false) %7B%0A
+                    printVertexe(i);%0A
             
@@ -918,33 +918,33 @@
        vertexes%5B
-x
+i
 %5D.setVisited(tru
@@ -1007,32 +1007,33 @@
 %7D%0A            %7D%0A
+%0A
         %7D%0A    %7D%0A
@@ -1140,24 +1140,256 @@
 %22 %22);%0A    %7D%0A
+%0A    public static void printAdjacent(int%5B%5D%5B%5D adjacent) %7B%0A%0A        for(int%5B%5D line:adjacent) %7B%0A            for(int i:line) %7B%0A                System.out.print(i + %22 %22);%0A            %7D%0A            System.out.println();%0A        %7D%0A    %7D%0A%0A
     public s
@@ -1552,21 +1552,8 @@
 ,'E'
-%7D; //,'D','E'
 ,'F'
@@ -1564,16 +1564,18 @@
 ,'H','I'
+%7D;
 %0A%0A      
@@ -1761,32 +1761,33 @@
 xesX;%0A        %7D%0A
+%0A
         drawGrap
@@ -1891,11 +1891,93 @@
 dge(
-2,3
+1,2);%0A        drawGraphForSearch.addEdge(2,3);%0A        drawGraphForSearch.addEdge(2,5
 );%0A 
@@ -2157,24 +2157,59 @@
 Adjacent();%0A
+%0A        printAdjacent(adjacent);%0A%0A
         entr

update the breadthfirst