// breadthfirst search - simple-minded
#include <iostream>
#include <queue>
#include <cstdlib>
using namespace std;
void bfs();
void getAllAdjacent(bool visited[],int, queue<int> &q);
const int n = 7;


int matrix[n][n] = {0,1,0,0,0,0,1,
                 1,0,0,1,0,0,0,
                 0,0,0,0,1,1,0,
                 0,1,0,0,1,1,1,
                 0,0,1,1,0,0,1,
                 0,0,1,1,0,0,0,
                 1,0,0,1,1,0,0};


int main ()
{
   bfs();
   system("pause");
   return 0;
}

void bfs()
{
   bool visited [n] = {false,false,false,false,false,false,false};
   int current = 0;
   queue <int> q;   
   visited [current] = true;
   q.push(current);
   while (!q.empty() )
   {
       current = q.front();
       cout << char(current+'a') << endl;
       q.pop();
       getAllAdjacent(visited,current,q);
   }
}

void getAllAdjacent(bool visited[],int current, queue <int> &q)
{
   // put all aunvisited vertices adjacent to current
   // onto queue
   for (int col= 0; col < n; col++)
      if (matrix[current][col]==1 && !visited[col])
      {
          q.push(col);
          visited[col] = true;
      }
}
