Question: Given the following implementation of vector: :push.back trace through the cost of the first 10 pushbacks, if a cheap pushback (i.e., a single copy) has
Given the following implementation of vector: :push.back trace through the cost of the first 10 pushbacks, if a "cheap" pushback (i.e., a single copy) has a cost of 1, and the initia size and capacity are 0. void vector: : push_back(int x) f if(size capacity) ( // Full, reallocate to make room int* old.data data; data new int[1 5 capacity 3]; // Copy everything to the new array for(int i 8; i capacity; ++i) data[i] old.data[i]; capacity 15capacity / 3; deletel] old.data; // Add new element datalsize++] x
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
