当前位置:网站首页>Sort() sort function
Sort() sort function
2022-06-13 09:14:00 【GAOJIN painting】
1. Standard sort : Yes int,double ,float And other data structure arrays
(1)#include<algorithm>
(2) grammar :sort(a,a+n,cmp);
explain :
1)cmp To judge by , If you do not write, the default is ascending
2) Achieve descending order sort(a,a+n,greater<T>())//T According to the array a Type determines
Implementation of integer arrays a, In descending order :sort(a,a+n,greater<int>())
//int a[n];n Represents a number , Is not a variable
int a[10];
sort(a,a+10)2. Custom sorting criteria —— make the best of cmp Determine whether the sorting function uses
The collection is written by bloggers , Don't write here .
Only on how to write according to custom guidelines cmp() Understand and sort out ;
bool cmp(int x,int y)
{
return x>y;
}
//.....
int main()
{
//..
sort(a,a+n,cmp);
}
(1) Realization function :int The type array is arranged from large to small
(2) understand :( Individual )cmp() by bool Type function , Returned to sort() by bool value , Next ,x And y The order of corresponds to a The order in which values are taken for judgment , therefore x The relative position of should be in the front , If true No change ,false Just change it . So the implementation will make a The large element in the array is in the front , Small numbers come after .
边栏推荐
- 20211104 为什么矩阵的迹等于特征值之和,为什么矩阵的行列式等于特征值之积
- LeetCode 6096. 咒语和药水的成功对数(二分查找)
- LeetCode 343. 整数拆分
- CAS无锁
- 20211108 differential tracker
- Tutorial (5.0) 02 Management * fortiedr * Fortinet network security expert NSE 5
- Neo4j環境搭建
- C language: minesweeping
- C language: deep understanding of character functions and string functions (2)
- Some websites of QT (software download, help documents, etc.)
猜你喜欢

Simulink variant model and variant subsystem usage

类的加载概述

20211104 为什么相似矩阵的迹相同

Installation of sonarqube code quality management platform (to be continued)

C language: dynamic memory management

JUC原子引用与ABA问题

Use typescript to complete simple snake eating function

Class loading overview

攻防世界PWN play 条件竞争漏洞的利用

20220524 如何把CoppeliaSim安装到D盘
随机推荐
an error occurred while trying to rename a file in the destination directory code 5
BGP 联邦+Community
20211020 academician all drive system
20211108 differential tracker
20220524 how to install coppeliasim to disk D
Mttr/mttf/mtbf diagram
20211108 A转置乘A是正定矩阵吗?A转置乘A是正定矩阵的充分必要条件是什么?
How excel adds hyperlinks to some text in a cell
Redis fuzzy query batch deletion
Tutorial (5.0) 01 Product introduction and installation * fortiedr * Fortinet network security expert NSE 5
How Simulink adds modules to the library browser
Batch read all voice files under the folder
基于微信小程序的图书馆管理系统.rar(论文+源码)
Neo4j environment construction
LeetCode 343. 整数拆分
LeetCode 201. 数字范围按位与
批量讀取文件夾下的全部語音文件
JUC atomic accumulator
20211104 为什么矩阵的迹等于特征值之和,为什么矩阵的行列式等于特征值之积
Detailed explanation of C language callback function