【问题标题】:using std::sort() on a list<int>在 list<int> 上使用 std::sort()
【发布时间】:2011-05-02 16:19:19
【问题描述】:

如何使用 std::sort() 函数对列表进行排序?下面的代码我试过了。

std::sort(listStorage.begin(), listStorage.end());

提前致谢。

【问题讨论】:

  • 对我来说看起来不错,我们可以看到listStorage的定义,初始值和输出吗?如果 listStorage 不是原始数据类型,则需要将比较函子作为第三个参数传递。
  • 抱歉,我错过了您在标题中指定了 listStorage 的内容。没关系,看看jwd的答案。

标签: file sorting linked-list ifstream


【解决方案1】:

尝试使用:

listStorage.sort();

链表不提供随机访问迭代器,这就是 std::sort 不起作用的原因。

【讨论】:

    猜你喜欢
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 2021-10-28
    相关资源
    最近更新 更多