#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
    const int N=5;
    string a[N]={"www","algorithm","racer","text","wait"};
    vector<string> b(a,a+5);//数组转化成向量
    for(size_t i=0;i<N;++i)
        cout<<b[i]<<" ";
    cout<<endl;

    sort(a,a+N);
    for(int i=0;i<N;++i)//使用sort进行数组排序
        cout<<a[i]<<" ";
    cout<<endl;

    sort(b.begin(),b.end());//向量正序排列
    for(const auto& x:b)
        cout<<x<<" ";
    cout<<endl;

    sort(b.rbegin(),b.rend());//向量倒序排列

    for(const auto& x:b)//基于范围的for循环
        cout<<x<<" ";
    cout<<endl;
    system("pause");
    return 0;
}

sort排序与二分查找

 

 sort排序与二分查找

 

相关文章:

  • 2022-02-03
  • 2021-09-21
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-09-11
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-05-19
  • 2021-12-19
  • 2022-12-23
  • 2021-03-31
  • 2021-11-06
相关资源
相似解决方案