Problem 12
a. It was remarked in this chapter that the performance of bubble sort can be improved if we stop the sorting process as soon as we find that in an iteration, no swapping of elements takes place. Write a function that implements bubble sort algorithm using this fact. b. Using the algorithm that you designed in part (a), find the number of iterations that are needed to sort the list: 65,14,52,43,75,25,80,90,95
Problem 13
Suppose that \(L\) is a sorted list of 4096 elements. What is the maximum number of comparisons made by binary search to determine whether an item is in \(\mathbf{L}\) ?
Problem 14
Suppose that the elements of a list are in descending order, and they need to be put in ascending order. Write a C+ + function that takes as input an array of items in descending order and the number or elements in the array. The function rearranges the element of the array in ascending order. Your function must not incorporate any sorting algorithms, that is, no item comparisons should take place.
Problem 15
To use a vector object in a program, which header file must be included in the program?
Problem 16
What do the following statements do?
a. vector
Problem 17
What is the output of the following C++ code?
vector
Problem 18
What is the output of the following C++ code?
vector
Problem 19
a. Write a C++ statement that declares secretList to be a vector object to store integers. (Do not specify the size of secretList.) b. Write C++ statements to store the following values, in the order given, into secretList: 56, 28, 32, 96, 75 c. Write a for loop that outputs the contents of secretList. (Use the expression secretList.size() to determine the size of secretList.)
Problem 20
. What is the output of the following C++ code?
vector
Problem 21
1\. Suppose that you have the following C++ code:
vector