Checkpoint 1 Write and test a function named reverse_vector that reverses the contents of an STL vector of integers. For example, if the contents of the vector are in increasing order before the call to reverse_vector, then they will be in decreasing order afterwards. For this checkpoint, use indexing/subscripting on the vector, not iterators (or pointers). You may not use a second vector or array. The trick is to step through the vector one location at a time, swapping values between the rst half of the vector and the second half. As examples, the value at location 0 and the value at location size()-1 must be swapped, and the value at location 1 and the value at location size()-2 must be swapped. Write a main function to test the function you have written. The main function should (a) create a vector of integers, (b) output the contents, (c) pass the vector to the reverse function, and then (d) output the resulting vector. To help with this, you should write an additional function that prints the size and the contents of a vector (so you dont need to keep writing for loops over and over). Your main function should test special cases of empty vectors and vectors of one or two values. Then you should test typical cases. Be sure to also test somewhat bigger vectors with both an even and an odd number of elements. To complete this checkpoint, show a TA the completed and correct reverse function and the test main function, and then show the TA the compilation and correct output. Checkpoint 2 Write a new version of the reverse function named reverse_list that instead uses iterators to reverse the contents of an STL list of integers. Add code to the main program to test this. (You can start by copying much of the code and test cases you wrote for Checkpoint 1). You may want to use a straightforward concept we did not discuss in lecture: a reverse iterator. A reverse iterator is designed to step through a list from the back to the front. An example will make the main properties clear: list
Programming
[Solved] SOLVED:Iterators & Linked Lists & Reversing Data solution
$25
File Name: SOLVED:Iterators_&_Linked_Lists_&_Reversing_Data_solution.zip
File Size: 536.94 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.