您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

C ++排序跟踪索引

C ++排序跟踪索引

使用C ++ 11,以下方法应该可以正常工作:

template <typename T>
std::vector<size_t> ordered(std::vector<T> const& values) {
    std::vector<size_t> indices(values.size());
    std::iota(begin(indices), end(indices), static_cast<size_t>(0));

    std::sort(
        begin(indices), end(indices),
        [&](size_t a, size_t b) { return values[a] < values[b]; }
    );
    return indices;
}
其他 2022/1/1 18:13:41 有546人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶