I've an unlimited number of dates / wxDateTimes (lets say 3-30)
is it possible to add them to a "list" and sort them?
Must i do that for my own, or is there a solution from wxwidgets?
sorting elements
sorting elements
wxWidgets is nice
Well, there are some comparison functions for wxDateTime, so you should be able to sort them. I suppose you could put them in a wxList and create your own sorting function to sort the list automatically.
Also, you can use the STL.
Unfortunately the wxDateTime has no operator<(), since the easiest way to sort with the STL is to use operator< just write your own.
Now you can use all the algorithms that the STL has at it's disposal. Like using a vector:
Or you can put them in a std::map or std::set, so you have them sorted all the time. Or use a std::list (wich hast std::list::sort). Or put them in an Array and use std::sort on it. Or...
Unfortunately the wxDateTime has no operator<(), since the easiest way to sort with the STL is to use operator< just write your own.
Code: Select all
bool operator< (const wxDateTime& lhd, const wxDateTime& rhd)
{
return lhd.IsEarlierThan(rhd);
}
Code: Select all
#include <vector>
#include <algorithm>
std::vector<wxDateTime> myDateTimes;
// Put your Datetimes in the Vector. e.g. myDateTimes.push_back(...)
std::sort(myDateTimes.begin(), myDateTimes.end());