When I call sortin vectorfrom doubleusing iterators begin()and end()how sortdoes the function modify the original vectorto contain sorted values?
sort
vector
double
begin()
end()
I, although iterators simply represented the value, so how could they force vectorme to modify the original ?
vector<double> nums = {10.33, 20.44, 60.77}; sort(nums.begin(), nums.end(); // how does the original nums get changed?
, , . , . , , (*it).
*it
. :
vector<double> nums = {10.33, 20.44, 60.77}; double* it = &nums[0]; //get the address of the first element ++it; //increment the pointer *it = 42; //assign 42 to nums[1]
( ).
vector<double> nums = {10.33, 20.44, 60.77}; vector<double>::iterator it = nums.begin();//get an iterator to the first element ++it; //increment the iterator *it = 42; //assign 42 to nums[1]
Source: https://habr.com/ru/post/1628952/More articles:How to use aws-cli with local dynamoDB? - amazon-dynamodbInvalid signed request: Missing required parameter - iosThe footer (navbar) does not apply to the sidebar - jqueryOsmdroid Bonuspack - MyLocationNewOverlay - javaVariadic template argument size (not counted) - c ++Specify the time interval in Django TimeStampedModel and Querying is pythonThe following build commands failed to execute: CompileC - iosSelect the last event before the specified date - mysqlmvn exec: exec with '<' on the command line Args - mavenAdding multiple SSL certificate certificates to Android KeyStore does not work. (from resource file) - javaAll Articles