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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -