【问题标题】:how can I acces nested pair in a vector by iterator?如何通过迭代器访问向量中的嵌套对?
【发布时间】:2018-05-19 14:57:33
【问题描述】:

我正在尝试通过迭代器访问向量中的嵌套对,但在代码块 IDE 中出现错误,请帮助我如何做到这一点?你可以在附图中看到我的代码。

#include<bits/stdc++.h>
using namestace std;

vector<pair<int , pair<int, bool> > > graph[1000000];
vector<pair<int , pair<int, bool> > >:: iterator it;

queue<int> Q;
int cost[1000000], visit[1000000];


void BFS(int s)
{
    Q.push(s)
    visit[s] = 1;
    while(!Q.empty() {
        int v = Q.front();
        Q.pop();
        for (it=graph[v].begin(); it != graph[v].end(); it++) {
            if(cost[it->first] == -1) {
                cost[it->first] = it->second->first + cost[v];
                Q.push(it->first);

            }

【问题讨论】:

标签: c++ vector iterator


【解决方案1】:
it->first.second

因为它是一个指针,但它指向的对是对本身,而不是指针。

【讨论】:

    猜你喜欢
    • 2014-07-31
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 1970-01-01
    相关资源
    最近更新 更多