Maximum and minimum of an array using minimum number of comparisons -

could somebody please help me identify whats the problem with the following code:

#include<bits/stdc++.h>
#include<iostream> 
using namespace std; 

void findminmax(vector<int> &v,int* add_great,int* add_small,int n,int i)
{
    while(i<(n-1)){
        if(v[i]>v[i+1]){
            if(v[i]>*add_great){ *add_great=v[i];}
            if(v[i+1]<*add_small){*add_small=v[i+1];}
        }
        else{
            if(v[i+1]>*add_great){*add_great=v[i+1];}
            if(v[i]<*add_small){*add_small=v[i];}
        }
        i+=2;
    }
    
}
int main() 
{   
    int n;
    cin>>n;
    std::vector<int> v;
    int great,small;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int i=0;
	if(n%2==0){
	    if(v[0]>v[1]){
	        great=v[0];
	        small=v[1];
	    }
	    else{
	        great=v[1];
	        small=v[0];
	        
	    }
	    i=2;
	}
	else{
	    great=v[0];
	    small=v[0];
	    i=1;
	}
	findminmax(v,&great,&small,n,i);
	cout<<small<<" "<<great<<"\n";
	return 0; 
} 

for(int i=0;i<n;i++){
        cin>>v[i];
    }

You are treating vector as an array.

Modify it to

for(int i=0;i<n;i++){
        int input;
        cin >> input;
        v.push_back(input);
    }

Other than this, there is no error in your code.

thanx aryan for giving time, i got it fixed by defining the size of the vector or else it can be fixed using your suggestion.