Im writing a program for breadth first traversal of a graph, it takes input from a file and calculates time taken for traversal and disconnected graphs. I get the error deque iterator not dereferenceable and dont really know what that means, ive tried reading the answers posted to questions before but couldn't make any sense of them. Please help me... Here is my code
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#include <string>
#include <iomanip>
#include <sstream>
#include <queue>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
using std::ofstream;
using std::ifstream;
using std::fstream;
using std::string;
using std::ios;
using std::istringstream;
using std::stringstream;
using std::vector;
using std::queue;
bool allVisited(vector<bool> );
static const int N=32;
int main(){
bool found;
int count=0;
clock_t start;
clock_t stop;
double time;
vector<vector<int> > matrix ( N, vector<int> ( N ) );
vector<bool> traversed;
for(int i=0;i<N;i++)
traversed.push_back(false);
queue<int> breadth_first;
ifstream myFile;
string line;
int offset;
myFile.open ("g32.data");
if(myFile.is_open()){
while(!myFile.eof()){
int p=0, q=0;
getline(myFile,line);
istringstream tokenizer(line);
string token,token1;
getline(tokenizer, token, ' ');
getline(tokenizer, token1, ' ');
istringstream first(token);
first >>p;
istringstream second(token1);
second >>q;
if(p==0||q==0)
continue;
else
matrix[p-1][q-1]=1;
}
}
start=clock();
int root=0;
traversed[root]=true;
breadth_first.push(root);
while(!breadth_first.empty() && !allVisited(traversed)){
for (int i=0; i<traversed.size(); i++){
if(matrix[root][i]!=0 && !traversed[i]){
cout<<"here";
traversed[i]=true;
breadth_first.push(i);
}
}
breadth_first.pop();
root=breadth_first.front();
}
stop=clock();
time=double(stop-start)/CLOCKS_PER_SEC;
for(int i=0; i<traversed.size(); i++)
if(traversed[i]==1)
count++;
cout<<"The Execution Time is :"<<time<<" Seconds"<<endl;
if(count==N)
cout<<"There were no Disconnected Graphs"<<endl;
system("PAUSE");
}
bool allVisited(vector<bool> v) {
for(int i=0; i<v.size(); i++)
if(v[i]==false)
return false;
return true;
}