如何在以下程序中分配向量

how assign vector in below program?

本文关键字:分配 向量 程序      更新时间:2023-10-16

任何人都可以告诉我这条线在下面的程序res.back().insert(end(res.back()), begin(ity->second), end(ity->second));,如何如何我想将元素分配为使用循环的元素,而不是上述语句,但会是如果您解释以上陈述是如何分配元素的,对我有好处的我如何使用循环进行同样的操作。

任务:https://leetcode.com/problems/vertical-order-order-traversal-of-a-binary-tree/

代码:https://ideone.com/e40syr

vector<vector<int>> verticalTraversal(TreeNode* r, vector<vector<int>> res = {}) {
    map<int, map<int, set<int>>> m;
    dfs(r, 0, 0, m);
    for (auto itx = m.begin(); itx != m.end(); ++itx) {
        res.push_back(vector<int>());
        for (auto ity = itx->second.begin(); ity != itx->second.end(); ++ity) {
            res.back().insert(end(res.back()), begin(ity->second), end(ity->second));
        }
    }
    return res;
}
res.back()

获得res中的最后一个元素。

.insert(end(res.back()),

在此位置插入一些东西。

begin(ity->second), end(ity->second)

要插入的迭代范围。

);

您可以分配这是

的循环
for (auto itz : ity->second)
  res.back().push_back(itz);