Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » How to sort a vector?
Re: How to sort a vector? [message #37852 is a reply to message #37844] Sun, 18 November 2012 12:27 Go to previous messageGo to previous message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
koldo wrote on Sat, 17 November 2012 00:34

Hello crydev

If MovieInfo has operator< it is easy, just call Sort(myvector);

If not, you can do this:

struct MySortWay {
	bool operator () (const MovieInfo& a, MovieInfo& b) const { 
		return a.value < b.value; // Just an example. It dependes on MovieInfo contents
	}
};

Vector <MovieInfo> myvector;

Sort(myvector, MySortWay);


Smile


Thanks Koldo, this makes sense to me. I tried it using the operator < which I created inside MovieInfo:

bool operator < (const MovieInfo& pComp) const
{
	return pComp.cFullPath > cFullPath;
};


However, the two Sort methods do not have the same algorithm! I have tried to find out another way of fixing my problem but since I am using callbacks to fill up my ArrayCtrl one item by another from another thread I'm having trouble finding out how I could sort on the fly.

The ArrayCtrl.Sort() and Sort(myVector) both sort alphabetically, but not exactly the same. What should I do to abandon this problem? Is there a way maybe to sort on the fly so I can keep my callback system?
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is libXi needed ??
Next Topic: To add serialize/xmlize/jsonize functions to EditField and others
Goto Forum:
  


Current Time: Fri May 10 21:07:15 CEST 2024

Total time taken to generate the page: 0.03309 seconds