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

stable_sort with arrays?

P: n/a
Is it possible to do something like this:

Team* League[4];

for (int team=0; team<4; team++)

{

League[team] = new Team;

}

std::stable_sort(League[0], League[3], TeamIsBetter );

***********************************

bool TeamIsBetter( Team* Team1, Team* Team2 )

{

int PointsTeam1 = Team1->GetPoints();

int PointsTeam2 = Team2->GetPoints();
return PointsTeam2 > PointsTeam1;

}
Aug 7 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Andreas Schmitt wrote:
Is it possible to do something like this:

Team* League[4];

for (int team=0; team<4; team++)

{

League[team] = new Team;

}

std::stable_sort(League[0], League[3], TeamIsBetter );
Use:

std::stable_sort(League+0, League+4, TeamIsBetter );

a) Pointers into an array can be used as iterators in generic algorithms
from the standard library.

b) std::stable_sort wants the second parameter to point *past* the end.

***********************************

bool TeamIsBetter( Team* Team1, Team* Team2 )

{

int PointsTeam1 = Team1->GetPoints();

int PointsTeam2 = Team2->GetPoints();
return PointsTeam2 > PointsTeam1;

}

Best

Kai-Uwe Bux
Aug 7 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.