0

I have an array which I want to convert in vector. I have this code :

int function(int A[], int K){
    vector<int> v,temp1,temp2;
    for(int i = 0; A[i] != 0; ++i) v.push_back(A[i]);
    sort(v.begin(), v.end());
    int n = v.size();
    cout << n << endl;
}

And I try this code with the following test :

int main(){
    int tab[] {4,9,8,2,6};
    int sol = function(tab,3);
    cout << sol << endl;
    return 0;
}

And it displays 18 while I expect 5 as a value, I don't understand why

0 Answers0