473,395 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 7801
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.