cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Beginners : sorted and shuffled vectors
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  sorted and shuffled vectors

kohline (2)
hi i"m new to c++ and became a program to insert some stuff.

there is a class called Cluster those clusters appear mostly as vector<Cluster>
if i define

Cluster cluster;

there is something like

cluster.size()

which will give me the number of elements inside my cluster. i now want to sort the vector<Cluster> with respect to the number of elements in my cluster.
afterwards i want to pick only the ones with less than 5 elements, and erase them from vector<Cluster>. afterwards i have to access the vector<Cluster> but i dont want the vector<Cluster> to be accessed from smallest to largest cluster.

are there some ideas how to achieve this?

thanks a lot

kohline
|
Mitsakos (343)
You can overload the operators "<", ">", "==" for your class and use the sort() function from the algorithms...
Using the "<" operator you can find which one has less than 5 elemnts and erase it.

afterwards i have to access the vector<Cluster> but i dont want the vector<Cluster> to be accessed from smallest to largest cluster.

Use random() to shuffle it...
|
kohline (2)
thanks a lot. i'll try this out and see how far i can get.
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us