Question #98363

Give a function template SEARCH that can be used to search an array of elements of any type and returns the index of the element, if found. Give both the function prototype and the function definition for the template. Assume a class template Array <T> is available.

Expert's answer

template <typename T>


class Array

{

public:

  T *arr;

  Array(): arr(0){};

  ~Array();

};



int SEARCH(T *mas, T element, int size)

{

  int i;

  for(i = 0; i < size; i++)

  {

    if(mas[i] == element)

    {

      return i;

    }

  }

}





LATEST TUTORIALS
APPROVED BY CLIENTS