Answer to Question #98363 in C++ for matimu

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.
1
Expert's answer
2019-11-11T16:33:51-0500

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;

    }

  }

}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS