Checkpoint 1: Big O Notation

Checkpoints 2 and 3 explore our implementation from lecture of the STL vector class. Please download: Attached in the email these files - vec.h and test_vec.cpp

Checkpoint 2

Write a templated non-member function named remove_matching_elements that takes in two arguments, a vector of type Vec< T> and an element of type T, and returns the number of elements that matched the argument and were successfully removed from the vector. The order of the other elements should stay the same. For example, if v, a Vec< int> object contains 6 elements: 11 22 33 11 55 22 and you call remove_matching_elements(v,11), that call should return 2, and v should now contain: 22 33 55 22. You should not create a new vector in your function.

Add several test cases to test_vec.cpp to show that the function works as expected. What is the order notation of your solution in terms of n the size of the vector, and e the number of occurences of the input element in the vector?

Checkpoint 3

Add a print member function to Vec to aid in debugging. (Note, neither remove_matching_elements nor print are not part of the STL standard for vector). You should print the current information stored in the variables m_alloc, m_size, and m_data. Use the print function to confirm your remove_matching_elements function is debugged. Also, write a test case that calls push_back many, many times (hint, use a for loop!) and observe how infrequently re-allocation of the m_data array is necessary.

To verify your code does not contain memory errors or memory leaks, use Valgrind and/or Dr. Memory on your local machine - see instructions on the course webpage: Memory Debugging. Also, submit your code to the homework server (in the practice space for lab 4), which is configured to run the memory debuggers for this exercise. To verify that you understand the output from Valgrind and/or Dr. Memory, temporarily add a simple bug into your implementation to cause a memory error or memory leak.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.