一、快速排序
Ⅰ. 格式
sort(arr+m,arr+n,cmp);
将数组 $ arr $ 中下标为 $ m $ 的元素到下标为 $ n-1 $ 的元素,按照定义的函数 $ cmp $ 中的规则排序。
Ⅱ. 排序规则
int cmp(const int &a,const int &b)
{
return a>b;
}
如上的排序规则为从大到小排序,当 $ a=b $ 时应返回 $ 0 $ 。可以对结构体排序。
必须包含头文件 。
sort(arr+m,arr+n,cmp);
将数组 $ arr $ 中下标为 $ m $ 的元素到下标为 $ n-1 $ 的元素,按照定义的函数 $ cmp $ 中的规则排序。
int cmp(const int &a,const int &b)
{
return a>b;
}
如上的排序规则为从大到小排序,当 $ a=b $ 时应返回 $ 0 $ 。可以对结构体排序。
必须包含头文件 。
作者: FysbbCZH
文章链接: https://blog.fysbbczh.top/posts/32547.html
版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 协议。转载请注明出处!如有问题请通过评论或邮件联系,感谢您的反馈。