C++中sort倒序排序
时间: 2023-09-05 13:12:14 浏览: 231
通过c++的sort函数实现成绩排序功能
在C语言中,可以使用sort函数进行排序。如果要实现倒序排序,可以使用自定义的比较函数来实现。以下是一个示例代码:
```
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b) {
return (*(int*)b - *(int*)a);
}
int main() {
int array = {3, 100, 45, 2, 0};
int size = sizeof(array) / sizeof(array<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [c++中逆序reverse和sort的使用](https://blog.csdn.net/secant007/article/details/114889177)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [C++的sort函数逆序排序](https://blog.csdn.net/u010889616/article/details/48394053)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文