C++数组排序泛型算法

  
//数组排序泛型算法
#include <vector>
#include <iostream>
#include <algorithm> //内置泛型算法头文件
using namespace std;

int main(int argc, char* argv[])
{
    int arr[5]={12, 45, 23, 68, 28};//待排序的数组
    int n =3;                        //需要排序的元素个数
    sort(arr, arr+n);                //排序数组
    for (int i = 0; i<5; ++i)        //打印出来看看效果
    {    
        cout<<arr[i]<<endl;
    }
        return 0;
}

猜你喜欢

转载自www.cnblogs.com/zyxnet/p/12051823.html