Practice Programs can generally be solved with a short program that directly applies the programming principles presented in this chapter.
Write a function template for a function that has parameters for a partially filled array and for a value of the base type of the array. If the value is in the partially filled array, then the function returns the index of the first indexed variable that contains the value. If the value is not in the array, the function returns −1. The base type of the array is a type parameter. Notice that you need two parameters to give the partially filled array: one for the array and one for the number of indexed variables used. Also, write a suitable test program to test this function template.
Write a template version of the iterative binary search from Display 14.8. Specify and discuss the requirements on the template parameter type.
Write a template version of the recursive binary search from Display 14.6. Specify and discuss the requirements on the template parameter type.