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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!