Recursive call of utilityFunction is not required if while loop is used. Correct recursive function should be as below.

void Graph::utilityFunction(list &queue, bool *visited){

list ::iterator i;

if (queue.empty())

return ;

int source = queue.front();

cout << source << " ";

visited[source] = true;

queue.pop_front();

for (i = adjacencyList[source].begin(); i != adjacencyList[source].end(); ++i) {

if (!visited[ * i]) {

visited[ * i] = true;

queue.push_back( * i);

}

}

utilityFunction(queue, visited);

}