dear programmers
I am in need of some help please.
I am trying to sort vector<time_tassending.
the following is by best go but needs some guide.
struct assending : public binary_function<time_t, time_t, bool{
bool operator()(time_t x, time_t y) {
return x y;
}
}
sort(time_vec.begin(), time_vec.end(), assending());
will this be the correct way to do it?
thanks 3 4172
Gary Wessle wrote:
dear programmers
I am in need of some help please.
I am trying to sort vector<time_tassending.
the following is by best go but needs some guide.
struct assending : public binary_function<time_t, time_t, bool{
bool operator()(time_t x, time_t y) {
return x y;
}
}
sort(time_vec.begin(), time_vec.end(), assending());
will this be the correct way to do it?
thanks
There is a standard version of your "assending" functor, called greater.
All you need to do is:
#include <algorithm>
// ...
sort(time_vec.begin(), time_vec.end(), greater<time_t>()) ;
See this link for details: http://www.sgi.com/tech/stl/greater.html
--
Alan Johnson
Gary Wessle wrote:
dear programmers
I am in need of some help please.
I am trying to sort vector<time_tassending.
the following is by best go but needs some guide.
struct assending : public binary_function<time_t, time_t, bool{
bool operator()(time_t x, time_t y) {
return x y;
}
}
sort(time_vec.begin(), time_vec.end(), assending());
will this be the correct way to do it?
thanks
There is a standard version of your "assending" functor, called
greater. All you need to do is:
#include <algorithm>
// ...
sort(time_vec.begin(), time_vec.end(), greater<time_t>()) ;
See this link for details: http://www.sgi.com/tech/stl/greater.html
--
Alan Johnson
On Jan 31, 4:18 am, Gary Wessle <phd...@yahoo.comwrote:
dear programmers
I am in need of some help please.
I am trying to sort vector<time_tassending.
the following is by best go but needs some guide.
struct assending : public binary_function<time_t, time_t, bool{
bool operator()(time_t x, time_t y) {
return x y;
}
As mentioned otherwere, this functionality is already present in the
std:: library.
>
}
sort(time_vec.begin(), time_vec.end(), assending());
will this be the correct way to do it?
No - this sorts in descending order. the correct way is
std::sort(time_vec.begin(), time_vec.end());
Plain and as simple as it can be right now.
/Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anand CS |
last post by:
Hi All
I have question regarding time data structures...
I have 64 bit unsigned microsecond resolution
(unsigned __int64 for windows/and unsigned long long for others)
variable. It stores the...
|
by: j0mbolar |
last post by:
i've read recently that time_t doesn't have to be in second resolution
but if it isn't, then what resolution could it be in?
microseconds, milliseconds, are all valid?
also, does anyone know...
|
by: Ian Pilcher |
last post by:
When adding two values of type time_t, how can I check for overflow?
Maybe I'm just brain-cramped today, but I can't figure out how to do it.
Thanks!
--...
|
by: Zwyatt |
last post by:
I have the following code (simplified here):
#include <time.h>
class A
{
public:
char *aString;
int aNum;
time_t aTime;
}
|
by: Zwyatt |
last post by:
having a really weird little bug w/ time_t...check it out:
I have the following code (simplified here):
#include <time.h>
class A
{
public:
char *aString;
int aNum;
| |
by: Henrik Goldman |
last post by:
I have strings like "2006-03-26 21.51" which I would like to convert into
time_t. I know that the string is in localtime.
So far I've written the following code:
time_t...
|
by: loudking |
last post by:
Hello, all
I don't quite understand what does ((time_t)-1) mean when I execute
"man 2 time"
RETURN VALUE
On success, the value of time in seconds since the Epoch is
retu
rned.
On error,...
|
by: Nick Keighley |
last post by:
Hi,
this is probably quite easy...
How do I convert a UTC string into a time_t?
eg. "2007-12-18 13:37:26" - a time_t.
Now FAQ 13.3 says use mktime() to convert a struct tm into
a time_t...
|
by: Abubakar |
last post by:
Hi,
Lets say I have three integers (date, month, and year) as part of a struct
lets say like
struct mydate{ int day, month, year};
I want to add x number of days to this date. And it should be a...
|
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...
|
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...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |