By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

Vector class

P: 1
Hi everyone, i have some issues with the vector class, actually i want to sort my vector or just find something within. I'm tryin to use <algorithm>, made for using list and vector, but it doesn't work very well.... i have many errors while compilating...
Here is the source code :

(struct centre with three integers, x y and mountain)

{
std::vector<centre> vec;
vec.reserve(500);
vec.at(1).x = w;
vec.at(1).y = u;
vec.at(1).mountain = z;
}

and then i use the method sort(vec.begin(), vec.end()); i'd like to sort my vector by mountain....
could you help me please ?? thanks
Mickael.
Mar 8 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
have a look at this simple example ov sorting avector
Expand|Select|Wrap|Line Numbers
  1.     int idata[]={1,5,7,4,9,78,45,23,56,-2,-8,56};
  2.     vector<int> v;
  3.     for (int i=0;i<sizeof(idata)/sizeof(int); i++) v.push_back(idata[i]);
  4.     for(int i=0;i<v.size();i++) cout << v[i] << " ";
  5.     cout << endl;
  6.     sort(v.begin(), v.end());
  7.     for(int i=0;i<v.size();i++) cout << v[i] << " ";
  8.  
it pushes the int data onto the vector then sorts it
Mar 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.