如何使用 std::sort 在 C++ 中对数组进行排序
在编程语言中,排序是一种基本功能,它应用于数据,将这些数据是升序还是降序排列。在C++程序中,有一个函数std::sort()用于对数组进行排序。
sort(start address, end address)
这里,
Start address => The first address of the element. Last address => The address of the next contiguous location of the last element of the array.
示例代码
#include输出结果#include using namespace std; void display(int a[]) { for(int i = 0; i < 5; ++i) cout << a[i] << " "; } int main() { int a[5]= {4, 2, 7, 9, 6}; cout << "\n The array before sorting is : "; display(a); sort(a, a+5); cout << "\n\n The array after sorting is : "; display(a); return 0; }
The array before sorting is : 4 2 7 9 6 The array after sorting is : 2 4 6 7 9
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下