473,503 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sorting time_t


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
Jan 31 '07 #1
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
Jan 31 '07 #2
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

Jan 31 '07 #3
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

Jan 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
25486
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...
6
7851
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...
8
4879
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! --...
0
1253
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; }
0
1431
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;
8
12320
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...
45
9297
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,...
7
5993
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...
8
4128
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...
0
7076
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
7323
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...
0
5576
agi2029
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,...
1
5005
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...
0
4670
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...
0
3162
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...
0
1507
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 ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
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...

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.