Because the elements between [hi,_size] are used to cover the elements in the [lo, _size+lo-hi] interval. hi increases to _size, and the corresponding lo will increase to _size+lo- hi, that is, _size+lo-hi is the position of the last element, that is, the new _size value
The code uses lo to mark the position of the last element, so the final size is _size=lo.
In this function, lo and hi are both value-passed parameters, that is, these two values are destroyed after the function is completed. is a member of vector. It uses _size to determine the number of elements saved. _sizeSo what needs to be modified here is , not _size. hi
hi is the right endpoint of the interval to be deleted at the beginning, and after while ends, it represents the right endpoint of the remaining elements; before _size is updated, it represents the right endpoint of the element before it is deleted, whileAfter the end, the unupdated _size is meaningless. What the hell is assigning hi to _size
lo and hi are local variables (parameters), and their scope is within the function. They are destroyed after the function is executed. It is meaningless to update hi.
represents the size of the vector _size, which is the value returned by calling v.size(), so _size
The line where you put the arrow has accumulated the variable lo
Because the elements between [hi,_size] are used to cover the elements in the [lo, _size+lo-hi] interval.
hi increases to _size, and the corresponding lo will increase to _size+lo- hi,
that is, _size+lo-hi is the position of the last element, that is, the new _size value
The code uses lo to mark the position of the last element, so the final size is _size=lo.
In this function,
lo
andhi
are both value-passed parameters, that is, these two values are destroyed after the function is completed.is a member of
vector
. It uses_size
to determine the number of elements saved._size
So what needs to be modified here is, not
_size
.hi
hi=_size
UnreasonableThe meaning of
should be updated
hi
is the right endpoint of the interval to be deleted at the beginning, and afterwhile
ends, it represents the right endpoint of the remaining elements; before _size is updated, it represents the right endpoint of the element before it is deleted,while
After the end, the unupdated _size is meaningless. What the hell is assigning hi to _sizelo
andhi
are local variables (parameters), and their scope is within the function. They are destroyed after the function is executed. It is meaningless to updatehi
.represents the size of the vector _size, which is the value returned by calling v.size(), so _size