How do I return a modified vector in c++? -


why (return a;) not work? error "no user-defined-conversion operator available can perform conversion, or operator cannot called."

how return newly sorted vector?

int sort(vector <int> a, int n) {     if( n >= 2 && n <= 43)     {         //sort vector         for(int j=2; j<=n; j++)         {             int tmp = a[j];             int = j-1;             while (-1<i && tmp < a[i])             {                 a[i+1] = a[i];                 i--;             }             a[i+1] = tmp;         }     }      return a; } 

you can go 1 of following 2 ways solve problem:

1) change return type of function vector

vector<int> sort(vector <int> a, int n){     // body of function } 

2) pass reference vector parameter. affect function prototype follows

int sort(vector <int> &a, int n){     // body of function } 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -