sort排序与二分查找

Posted wangtianning1223

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sort排序与二分查找相关的知识,希望对你有一定的参考价值。

#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排序与二分查找的主要内容,如果未能解决你的问题,请参考以下文章