int arr[4]={1,3,2,4};
sort(arr,arr+4);
//排序结果是 1,2,3,4
//通过自定义规则进行排序
bool map(int x1,int x2){
return x1>x2;
}
int arr[5]={3,2,1,4,5};
sort(arr,arr+n,map);
//排序结果是 5,4,3,2,1
//规则的位置不仅可重载大小于号,还可以重载其他符号
int arr[4] = {1,2,3,4}; // 升序数组
bool judge1 = binary_search(arr, arr+4, 1); // judge1结果为true
bool judge2 = binary_search(arr, arr+4, 5); // judge2结果为false
//binary_search利用的也是指针
int arr[5] = {1,2,4,5,6};
int c = lower_bound(arr,arr+5,4)-arr;
// c的值就是2
int arr[5] = {1,2,2,4,5};
auto bounds = equal_range(arr, arr+5, 2);//auto是自动判断定义类型
int a = bounds.first-arr; // a结果为1
int b = bounds.second-arr; // b结果为3
copy:
int arr1[4] = {1,3,2,4};
int arr2[4];
copy_n(arr1, 4, arr2);
c++部分函数演示
最新推荐文章于 2024-07-16 18:00:34 发布