LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2004, 02:19 PM   #1
nodger
Member
 
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192

Rep: Reputation: 30
looking for an elegant (and fast) solution


Heres what I am trying to do: I have a load of HTML files sorted into days, ie. One for each day, and I have them in a directory structure with one directory for each day of the month, all contained within one directory, and liikewise all months in one directory for that year.

Code:
For example.
                                          ____________ROOT____________
                                        /                                                                  \
                               ___2003_______                             _____2004_____________
                             /    |       |       |           \                          /          |              |             |          \
                         Jan  Feb Apr  Jun      Jul                      Jan    Mar       Jun        Jul       Sep
                        /   |               |  \
                       2  4            12   31

etc etc.

Not every day will have a directory, or every month etc

What I want is an algorithm that will take one unsigned integer that will go back a certain number of "updates" and pull out the HTML file (or give me a path to it), for example if the last 4 updates were on the 26th of April,and the 1st,2nd and 4th of May 2004 and I gave it the number 2, it would give me the third least recent one, ie the one for the 1st of May.

This seems like an easy problem but im having problems finding a simple fast elegant solution to it. and any help would by appreicated. Thanks
 
Old 05-10-2004, 03:00 PM   #2
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
1. Create a list of update dates (traverse the directory, grab the dir names, etc.)
2. Sort that list in date order
3. Find the date corresponding to the given index.
4. Use the directory corresponding to that date.
 
Old 05-10-2004, 03:41 PM   #3
nodger
Member
 
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192

Original Poster
Rep: Reputation: 30
mmm...you`re probably right. I hate sorting
 
Old 05-10-2004, 03:55 PM   #4
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Look into qsort (google)
 
Old 05-10-2004, 05:03 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
You don't need sorting if you'd name the directories to 'sort' them using the directory structure. Years are sorted, months can be if you use 01 for Jan, 02 for Feb and so on, days also can be if you use '01' instead of '1'.
 
Old 05-10-2004, 07:21 PM   #6
nodger
Member
 
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192

Original Poster
Rep: Reputation: 30
thats a good Idea, Mara. Ive implemented the quicksort aggorithm before, but I`d rather not usi it if I don`t have to
 
Old 05-11-2004, 11:27 AM   #7
nodger
Member
 
Registered: Oct 2003
Location: Ireland
Distribution: Slackware 9.1, Ubuntu
Posts: 192

Original Poster
Rep: Reputation: 30
Finished! - Ive got a solution I`m happy with.
 
Old 05-11-2004, 11:56 AM   #8
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Thumbs up

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware is elegant, but... Pete Abel Slackware 6 10-26-2004 03:24 PM
Slackware is elegant, but... Pete Abel Linux - Software 3 10-26-2004 11:22 AM
XMMS fast farwarding randomly - Solution kaega2 Linux - Software 1 08-11-2004 10:39 PM
A solution to fast sound in kde 3.2.x TheOneAndOnlySM Linux - General 0 05-12-2004 09:56 PM
New Kernel and Alsa - an elegant way? Misel Slackware 5 10-30-2003 12:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration