Why my code is wrong


#1

template
int index_of_largest(T array[],int size){
int largeIndex = 0;
for(int i =0;i < size-1;++i){
if(array[i] >= array[i+1] ){
largeIndex = i;
}else{largeIndex = i+1;}
}
return largeIndex;
}


#2

You are not looking for maximum value in the array. You are just comparing two consecutive values.

template <class T>
T index_of_largest(T arr[], int n){
    int index = -1;
    T max = arr[0];
    
    for(int i=0; i<n ; i++){
        if(arr[i]>= max) {
            max = arr[i];
            index = i;
        }
    }
    return index;
}