linux multi -threaded foundation 2

2023-01-23   ES  

This articlehas a certain amount of omissions, and the article is first in Google’s search results. Therefore, I recorded this article as notes.

  • Understand the basic usage of C ++

Use the header file required by the sort () functionalgorithm
Sort function’s first parameter is
target array, the address that needs to be arranged
The second parameter is the focus described in this article

If you understand it in a simple way:

SORT’s arrangement range is a left closed and right open range: [The address corresponding to the first parameter, the address corresponding to the second parameter)
在这里插入图片描述

In other words, the following example code meets expectations:

int a [100]; 
 .... // Enter 20 numbers in some ways, corresponding to A [0] to A [19] 
 sort (a, a+20); // arrange the elements from 0 to 19 for elements to arrange the elements of 0 to 19

and sort () essentially logical relationship, please see the figure below:

在这里插入图片描述
int x[5]as an example, the data width of each element is 4, when the first element is referenced (

When the address of&a[0]), the address of the data head is actually quoted

Since the virtual address space occupied by the array is continuous, when passing the second parameter to SORT, if the parameter passed is the address of the fifth element, then the actual parameter is the data header of the fifth element. The address (the same address as the data tail of the fourth element)

So, the scope of the sort function is macroLeft closed and right open range: [The address corresponding to the first parameter, the address corresponding to the second parameter)

Vector container built -in method.end()The address returned is the end address of the last element, please see the figure below:
在这里插入图片描述
Therefore, the following code is in line with expectations

sort(x.begin(),x.end());

source

Related Posts

C Language’s use of Youth In

Collection -01 -Comparable and Comparators

[Play to Pointpillars] Pillarscatter operation

Protective measures for vulnerabilities of Android application

linux multi -threaded foundation 2

Random Posts

Ruby On Rails Oracle Configure Oracleenhanced, Ruby-OCI8 installation, ORA-12154: TNS

Solution SwipeRefreshLayout and ScrollView sliding conflict

SAP-Abap Learning Record (2)

zabbix email alarm

Quartz Deploy Table ‘HeartBeat.qrtzLocks’ DOESN’T Exist