472,358 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

Sort Function

Hi!!

I need something like a "sortfunction" because i want to sort the files
in a directory x by name or date. i can't find any system function in
c++ - any ideas, examples??

Thx,
SteM

Jul 22 '05 #1
5 7730
St**@wic.co.at writes:
Hi!! I need something like a "sortfunction" because i want to sort the files
in a directory x by name or date. i can't find any system function in
c++ - any ideas, examples??

I don't really know what you mean when you say 'something like a
"sortfunction"' or 'i can't find any system function in c++'.

How have you tried to look? Try Google and search for
C++ sort
.. But you'll still need to do some work to get info about files.

Jul 22 '05 #2
St**@wic.co.at wrote:
Hi!!

I need something like a "sortfunction" because i want to sort the files
in a directory x by name or date. i can't find any system function in
c++ - any ideas, examples??

Thx,
SteM


std::list has a sort operation:

void sort ()
Sort the elements.
template<typename StrictWeakOrdering> void sort (StrictWeakOrdering)
Sort the elements according to comparison function.

In addition to that, check out <algorithm>.
I guess there's lots of sorting algos implemented in there.

Regards,
Matthias
Jul 22 '05 #3
> I need something like a "sortfunction" because i want to sort the files
in a directory x by name or date. i can't find any system function in
c++ - any ideas, examples??


Hmm.. what about std::sort?

# include <algorithm>

class File
{
};
void by_name(std::vector<File> &files)
{
std::sort(files.begin(), files.end());
}
bool date_compare(const File &f1, const File &f2)
{
if ( f1.date() < f2.date() )
return true;

return false;
}

void by_date(std::vector<File> &files)
{
std::sort(files.begin(), files.end(), date_compare);
}
Jonathan
Jul 22 '05 #4

"Jonathan Mcdougall" <jo***************@DELyahoo.ca> wrote in message
news:2d*********************@wagner.videotron.net. ..

bool date_compare(const File &f1, const File &f2)
{
if ( f1.date() < f2.date() )
return true;

return false;
}


How about just:

return (f1.date() < f2.date());

?

-Howard
Jul 22 '05 #5
>>bool date_compare(const File &f1, const File &f2)
{
if ( f1.date() < f2.date() )
return true;

return false;
}
How about just:

return (f1.date() < f2.date());


Thanks for the constructive answer.
Jonathan
Jul 22 '05 #6

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

Similar topics

18
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn,...
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
4
by: Seeker | last post by:
Hi, I have an array of objects. My object definition is given below: function tempArray(code,height,weight) { this.code = code; this.height = height; this.weight = weight; }
7
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I...
7
by: Ireneusz SZCZESNIAK | last post by:
I want to sort a vector with the std::sort function. There are two functions: one with two arguments, the other with three arguments. I am using the one with three arguments. I noticed that...
5
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need...
7
by: Stuart | last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the degenerate case in a common situation). I have a replacement. I would like to globally do "using namespace std; except use my...
20
by: Xah Lee | last post by:
Sort a List Xah Lee, 200510 In this page, we show how to sort a list in Python & Perl and also discuss some math of sort. To sort a list in Python, use the “sort” method. For example: ...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
18
by: xahlee | last post by:
Last year, i've posted a tutorial and commentary about Python and Perl's sort function. (http://xahlee.org/perl-python/sort_list.html) In that article, i discussed a technique known among...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.