Organizing Vector

Hello,
I was wondering how I could possibly organize one vector by placing it into an another. (Note: They are vector of objects). What i have so far is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
double done;
for ( int i = 0; i < id; i++ )
{
	done = guy[i].done();
	int smallest = i;
	for( int j = i + 1; j < id; j++ ){
		if( done > guy[j].done() )
			{
				done = guy[j].done();
				smallest = j;	
			}
		}
	newGuy.push_back( guy[smallest] );
}


This doesn't organize every part of the vector, and sometimes even copies the same guy into the newGuy. Any ideas?
What are you trying to do?
Put each "guy" in order according to there "done()" and placing it in "newGuy"
You mean that you want guy unsorted and newGuy sorted?

Like so:
1
2
3
4
5
6
7
8
9
10
class guy_obj // assuming guy consists of this
{
  bool operator<(const guy_obj &that_guy) const
  {
    return done() < that_guy.done();
  }
};
...
newGuy = guy;
std::sort(newGuy.begin(), newGuy.end());


See:
http://cplusplus.com/reference/algorithm/sort/

You can also sort without the overloaded operator<
Topic archived. No new replies allowed.