473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

stable_sort with arrays?

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
1 2567
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: William Payne | last post by:
Hello, in my program I have a std::vector of structs, a struct such as: enum Type { TYPE_FILE, TYPE_FOLDER }; struct Entry {
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
2
by: bill | last post by:
Hi, I just spent a loooooooong day to debug a problem, it ended up that sort() does not work properly on my vector!!! In the program I have a vector and the program dynamically add some new...
6
by: John Black | last post by:
I have a sort statement for vectr like this, sort(vec.begin(), vec.end(), EleSmaller); in running I find that the sort procedure falls into an endless loop, by adding some debug statement I...
6
by: Andreas Schmitt | last post by:
Hi, with myTeam being a vector of pointers to a class 'Team' std::vector<Team*> myTeam; I tried to use these two methods in the class 'League'
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
12
by: sandy | last post by:
Hello C++ Guru, I am using STL stable_sort to sort the vector string data using below code. #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.