You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the exercise asks what the program does, it's worth noting what the capacity will be at the end of the program instead of what it is after the program reads the words.
(a) The capacity will be at least 1,024 -- reserve sets the capacity to be enough to hold at least the specified amount. Since half-again 256 is still less than 1,024, no reallocation occurs during the resize, so the capacity stays the same.
(b) The capacity will be at least 1,024 -- half again 512 is still less than 1,024, so no reallocation occurs.
(c) The capacity will be at least 1,500 -- half again 1,000 is greater than 1,024, so reallocation occurs during the resize, changing the capacity to be at least the resize amount.
(d) The capacity will be at least 1,572 -- after reading 1,025 words, reallocation is likely to occur before reading the remaining 23 words ("likely" because it depends on whether the original allocation was 1,024 or greater than that.) The capacity after reading the full 1,048 words, then, depends on the implementation. If it's more than 1,572, the resize won't require an additional reallocation, but we know that the final capacity cannot be less than that because of the resize.
The text was updated successfully, but these errors were encountered:
Since the exercise asks what the program does, it's worth noting what the capacity will be at the end of the program instead of what it is after the program reads the words.
(a) The capacity will be at least 1,024 -- reserve sets the capacity to be enough to hold at least the specified amount. Since half-again 256 is still less than 1,024, no reallocation occurs during the resize, so the capacity stays the same.
(b) The capacity will be at least 1,024 -- half again 512 is still less than 1,024, so no reallocation occurs.
(c) The capacity will be at least 1,500 -- half again 1,000 is greater than 1,024, so reallocation occurs during the resize, changing the capacity to be at least the resize amount.
(d) The capacity will be at least 1,572 -- after reading 1,025 words, reallocation is likely to occur before reading the remaining 23 words ("likely" because it depends on whether the original allocation was 1,024 or greater than that.) The capacity after reading the full 1,048 words, then, depends on the implementation. If it's more than 1,572, the resize won't require an additional reallocation, but we know that the final capacity cannot be less than that because of the resize.
The text was updated successfully, but these errors were encountered: