C++的sort

文章目录

  • sort在#include<algorithm>的c++标准库中

  • 三参数
    void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);

  • 要排序的数组的起始地址。

  • 是结束的地址(最后一个数据的后一个数据的地址)

  • comp是排序的方法:可以是从升序也可是降序。

    • 不写,则默认从小到大

例子

#include<iostream>
#include<algorithm>
using namespace std;
main()
{
  int a[]={45,12,34,77,90,11,2,4,5,55};
  sort(a,a+10);
  for(int i=0;i<10;i++)
  cout<<a[i]<<" ";     
}

参考链接

  • https://www.cnblogs.com/junbaobei/p/10776066.html
发布了558 篇原创文章 · 获赞 295 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/zhoutianzi12/article/details/105175673