C ++ Deque迭代器不可解除引用

时间:2014-02-21 01:07:02

标签: c++ breadth-first-search dereference deque

我正在编写一个用于广度优先遍历图形的程序,它从文件中获取输入并计算遍历和断开图形所用的时间。我得到错误deque迭代器不能解除引用,并且不知道这意味着什么,我已经尝试过阅读之前发布的问题的答案但是对它们没有任何意义。请帮帮我......这是我的代码

#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;
}

0 个答案:

没有答案