473,659 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_sor t(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 2578
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_sor t(League[0], League[3], TeamIsBetter );
Use:

std::stable_sor t(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_sor t 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
1983
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
2840
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 > >pointer-to-array-of-size-N-of-type-T (which is fine) and not having type > >array-of-size-N-of-type-T (with some exceptions, which is curious). > > So far > >the consensus seems to be that while everyone is aware of this no one knows
2
1679
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 elements to the vector, but after each time an element is added, I call sort() against this vector, and start over again. Then there are some strange probelms, in debugging them, I found that sort() falls into some wild state, its pointers of vector...
6
2885
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 see sort is endlessly doing some comparision on non-exist number! Then I replace sort() with stable_sort(), it works fine. This really confuses me, what might be the reason of such problem? The vector seems
6
1538
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
29242
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); pfiles = ld.GetFiles("*.aspx.resx|") + ld.GetFiles("*.ascx.resx") + ld.GetFiles("*.master.resx"); but of course there is no + operation allowed on the FileInfo arrays returned by the GetFiles method.
1
8697
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 Framework are said to have an element type. http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
41
4928
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 the hash are alphabetically sorted if the key happens to be alpha numeric. Which I believe makes sense because it allows for fast lookup of a key.
12
2683
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
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.