sort排序与二分查找

#include
#include
#include
#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;ii)
        cout<" ";
    cout<<endl;

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

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

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

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

 

 

 

转载于:https://www.cnblogs.com/wangtianning1223/p/11431039.html

你可能感兴趣的:(sort排序与二分查找)