In this HackerRank Day 21: Generics problem solution Write a single generic function named printArray; this function must take an array of generic elements as a parameter (the exception to this is C++, which takes a vector). The locked Solution class in your editor tests your function.

HackerRank Day 21: Generics problem solution


Problem solution in Java programming.

public static <E> void printArray(E[] input)
{
    for(int i=0; i<input.length; i++)
    {
        System.out.println(input[i]);
    }
}




Problem solution in C++ programming.

// Add your code here
template <class T>
void printArray(vector<T> a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<"\n";
    }
}