c++ - Qsort 或对 unordered_set 排序

标签 c++ sorting qsort unordered-set

我有一个名为方程式的 unordered_set。我不是要排序或 qsort 是,这是我运行的代码行:

qsort(&equations, equations.size(), sizeof(string), strcmp);

我得到的错误是:

error: cannot convert 'std::unordered_set<std::basic_string<char> >' to 'void*' 
       for argument '1' to 'void qsort(void*, size_t, size_t, __compar_fn_t)'                   
qsort(equations, equations.size(), sizeof(string), strcmp); 

最佳答案

您需要将 unordered_set 复制到 vector 中并对其进行排序。

同样使用STL算法进行排序:

std::sort(v.begin(), v.end());
std::sort(v.begin(), v.end(), std::greater<int>());

关于c++ - Qsort 或对 unordered_set 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35360124/

相关文章:

C++ 串行通信问题

scala - 粗略(或部分)排序 Scala 中的列表

arrays - 如何在swift 3中按自定义状态值对自定义对象数组进行排序?

c - 如何在 C 中对结构数组进行排序?

c++ - C/C++ 高效sock反向代理

c++ - TCP推拉套接字服务器设计

c++ - 如何在解决方案资源管理器中保留源文件夹层次结构?

ios - 使用 NSLocale zh_Hans_CN 在 iOS 上的中文数字排序顺序不正确?

c - 在 C 中使用 qsort/casting

qsort 比较函数中的 const 限定符