bfsTree为空,未使用值警告

时间:2016-08-20 06:33:34

标签: c++ c++11

我正在尝试实现bfsTree。它应该将图形作为输入并将bfs树作为输出。但是,将边缘添加到bfs树的行似乎不起作用。 bfstree是空的。我认为这与这个未使用的价值警告有关。为什么会发出警告?以及如何解决它?感谢。

这是警告:

vertex.cpp:35:10: warning: expression result unused [-Wunused-value]
for (neighbor; neighbor != this->_neighbors.end(); neighbor++) {

这是bfs树代码片段:

Graph Bicc::breadthFirstSearch(Graph& sparseGraph) {
    Graph bfsTree;

    auto lev = 0;
    vector<Vertex> verticies = sparseGraph.getVerticies();
    for(int i = 0; i < verticies.size(); i++){
        verticies[i].color = "white";
        verticies[i].level = lev;
    }

    Vertex start = verticies[0];
    list<Vertex> VertexQueue;
    VertexQueue.push_back(start);

    while (!VertexQueue.empty())    
    {
        Vertex current = VertexQueue.front();
        current.color = "gray"; //current vertex is being processed
        auto neighbors = current.getNeighbors();

        //process all neighbors of current vertex
        for(auto n = neighbors.begin(); n != neighbors.end(); n++) {

            if (n->color == "white") {   // This is an unvisited vertex
                n->level = lev + 1;          // Set level
                n->parent = &current;       // Set parent
                n->color = "gray";          // Set color visited
                bfsTree.add(current, *n); //add the edge to bfsTree
                VertexQueue.push_back(*n);    // Add it to the queue    
            }
        }
        VertexQueue.pop_front();    // Pop out the processed vertex
        ++lev;  // The next level
    }
    return bfsTree;
}

以下是警告调用的vertex.cpp代码段:

bool Vertex::hasNeighbor(const Vertex& vertex) const {
    auto neighbor = this->_neighbors.begin();
    for (neighbor; neighbor != this->_neighbors.end(); neighbor++) {
        if (*neighbor == vertex) {
            break;
        }
    }
    return neighbor != this->_neighbors.end();
}

0 个答案:

没有答案