• C++ STL sort


    #include <iostream>
    #include <deque>
    #include <algorithm>
    #include <functional>

    using namespace std;

    int main()
    {
      deque<int> deque1;
      for (int k=0;k<15;k++)
      {
        deque1.push_back(rand());
      }

      deque<int>::iterator deq_iter1;
      for (deq_iter1 = deque1.begin(); deq_iter1 != deque1.end();++deq_iter1)
      {
        cout << *deq_iter1 << " ";
      }
      cout << endl;
      cout << "--------------------------------------------" << endl;

      sort(deque1.begin(), deque1.end());

      for (deq_iter1 = deque1.begin(); deq_iter1 != deque1.end(); ++deq_iter1)
      {
        cout << *deq_iter1 << " ";
      }
      cout << endl;
      cout << "--------------------------------------------" << endl;

      random_shuffle(deque1.begin(), deque1.end());

      for (deq_iter1 = deque1.begin(); deq_iter1 != deque1.end(); ++deq_iter1)
      {
        cout << *deq_iter1 << " ";
      }
      cout << endl;
      cout << "--------------------------------------------" << endl;

      sort(deque1.begin(),deque1.end(),greater<int>());

      for (deq_iter1 = deque1.begin(); deq_iter1 != deque1.end(); ++deq_iter1)
      {
        cout << *deq_iter1 << " ";
      }
      cout << endl;
      cout << "--------------------------------------------" << endl;

      random_shuffle(deque1.begin(), deque1.end());

      sort(deque1.begin(), deque1.end(), less<int>());

      for (deq_iter1 = deque1.begin(); deq_iter1 != deque1.end(); ++deq_iter1)
      {
        cout << *deq_iter1 << " ";
      }
      cout << endl;
      cout << "--------------------------------------------" << endl;

      system("pause");
      return 0;
    }

    =========================================================

    41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961
    --------------------------------------------
    41 5705 6334 9961 11478 15724 16827 18467 19169 23281 24464 26500 26962 28145 29358
    --------------------------------------------
    15724 26962 16827 23281 18467 19169 24464 9961 29358 5705 26500 11478 28145 6334 41
    --------------------------------------------
    29358 28145 26962 26500 24464 23281 19169 18467 16827 15724 11478 9961 6334 5705 41
    --------------------------------------------
    41 5705 6334 9961 11478 15724 16827 18467 19169 23281 24464 26500 26962 28145 29358
    --------------------------------------------
    请按任意键继续. . .

  • 相关阅读:
    Effective_STL 学习笔记(四十) 使仿函数类可适配
    Effective_STL 学习笔记(三十九) 用纯函数做判断式
    PMP考试大纲
    小技巧
    git 常用命令
    java web的返回值对象
    工作任务-SM敏捷核心思维
    树莓派上手
    spring 公用异常处理
    前端现在版本怎么这么乱
  • 原文地址:https://www.cnblogs.com/herd/p/11012626.html
Copyright © 2020-2023  润新知